import { SafeNSoundError } from '#util/error.js'; import Joi from 'joi'; /** * Generic authentication DTO. */ export class AuthDto { static schema = new Joi.object({ password: Joi.string().required(), username: Joi.string(), email: Joi.string().email() }).or('username', 'email'); username; email; password; static async create(data) { const obj = new AuthDto(); for (const key of Object.keys(data)) { if (key in obj) { obj[key] = data[key]; } } try { return await AuthDto.schema.validateAsync(obj); } catch (e) { console.log(e); throw new SafeNSoundError({ errCode: 'JOI_VALIDATION_ERROR', message: e.message, validation_details: e.details }); } } }