@@ -81,30 +81,6 @@ export class CreateUser {
 | 
			
		||||
            throw new UsernameOrEmailNeededError();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (this.group) {
 | 
			
		||||
            if (!Array.isArray(this.group)) {
 | 
			
		||||
                this.group = [this.group]
 | 
			
		||||
            }
 | 
			
		||||
            const groupIDs: number[] = this.group
 | 
			
		||||
            let errors = 0
 | 
			
		||||
            const validateusergroups = async () => {
 | 
			
		||||
                let foundgroups = []
 | 
			
		||||
                for (const g of groupIDs) {
 | 
			
		||||
                    const found = await getConnectionManager().get().getRepository(UserGroup).find({ id: g });
 | 
			
		||||
                    if (found.length === 0) {
 | 
			
		||||
                        errors++
 | 
			
		||||
                    } else {
 | 
			
		||||
                        foundgroups.push(found[0])
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                newUser.groups = foundgroups
 | 
			
		||||
            }
 | 
			
		||||
            await validateusergroups()
 | 
			
		||||
            if (errors !== 0) {
 | 
			
		||||
                throw new UserGroupNotFoundError();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        newUser.email = this.email
 | 
			
		||||
        newUser.username = this.username
 | 
			
		||||
        newUser.firstname = this.firstname
 | 
			
		||||
@@ -113,8 +89,34 @@ export class CreateUser {
 | 
			
		||||
        newUser.uuid = uuid.v4()
 | 
			
		||||
        newUser.phone = this.phone
 | 
			
		||||
        newUser.password = await argon2.hash(this.password + newUser.uuid);
 | 
			
		||||
        newUser.groups = await this.getGroups();
 | 
			
		||||
        //TODO: ProfilePics
 | 
			
		||||
 | 
			
		||||
        return newUser;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async getGroups() {
 | 
			
		||||
        if (!this.group) { return null; }
 | 
			
		||||
        let groups = new Array<UserGroup>();
 | 
			
		||||
        if (!Array.isArray(this.group)) {
 | 
			
		||||
            this.group = [this.group]
 | 
			
		||||
        }
 | 
			
		||||
        const groupIDs: number[] = this.group
 | 
			
		||||
        let errors = 0
 | 
			
		||||
        const validateusergroups = async () => {
 | 
			
		||||
            for (const g of groupIDs) {
 | 
			
		||||
                const found = await getConnectionManager().get().getRepository(UserGroup).find({ id: g });
 | 
			
		||||
                if (found.length === 0) {
 | 
			
		||||
                    errors++
 | 
			
		||||
                } else {
 | 
			
		||||
                    groups.push(found[0])
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return groups;
 | 
			
		||||
        }
 | 
			
		||||
        await validateusergroups()
 | 
			
		||||
        if (errors !== 0) {
 | 
			
		||||
            throw new UserGroupNotFoundError();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user