asmer@controller %!s(int64=5) %!d(string=hai) anos
pai
achega
233df53479
Modificáronse 1 ficheiros con 7 adicións e 4 borrados
  1. 7 4
      models.js

+ 7 - 4
models.js

@@ -16,12 +16,19 @@ module.exports = async (dbName='shop-roles') => {
 
             async save(...params){
                 console.log(this)
+                let otherUserWithThisLogin = this.login && await SlicedSavable.m.User.findOne({login: this.login})
                 if (this._id){
+                    if (otherUserWithThisLogin && otherUserWithThisLogin._id.toString() !== this._id.toString()){
+                        throw new ReferenceError(`User ${this.login} already exists`)
+                    }
                     if (!acl.includes('admin') && this.originalACL.toString() !== this.acl.toString())
                         throw new ReferenceError(`Not enough permissions for changing acl on ${this.login}`)
                     else return await super.save(...params)
                 }
                 else {
+                    if (otherUserWithThisLogin){
+                        throw new ReferenceError(`User ${this.login} already exists`)
+                    }
                     await super.save(...params)
                     this.___owner = this._id.toString()
                     this.acl      = [this.___owner, "user"]
@@ -113,10 +120,6 @@ module.exports = async (dbName='shop-roles') => {
                 }
             }
 
-            static get guestRelations(){
-                return ["categories", "orderGoods"]
-            }
-
             static get defaultPermissions(){
                 return {
                     create: ['admin'],