summary refs log tree commit diff
path: root/src/dto/auth/RegisterDto.js
blob: fa319b28665109ed52137b45404bf27b31b642de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { SafeNSoundError } from '#util/error.js';
import Joi from 'joi';

export class RegisterDto {
    static schema = new Joi.object({
        username: Joi.string().required(),
        email: Joi.string().email().required(),
        password: Joi.string().required(),
        type: Joi.string().valid('user', 'monitor', 'admin').required()
    });

    username;
    email;
    password;
    type = 'user';

    static async create(data) {
        const obj = new RegisterDto();
        for (const key of Object.keys(data)) {
            if (key in obj) {
                obj[key] = data[key];
            }
        }

        return await RegisterDto.schema.validateAsync(obj);
    }
}