summary refs log tree commit diff
path: root/src/dto
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-06-02 12:16:30 +0200
committerRory& <root@rory.gay>2025-06-02 12:16:30 +0200
commitea65ae3a11e03fa66f809be89f86baabf627ad82 (patch)
tree377af52ba925269feea603ab716fd52d950154bb /src/dto
parentFix readme (diff)
downloadnodejs-final-assignment-ea65ae3a11e03fa66f809be89f86baabf627ad82.tar.xz
Try to fix auth
Diffstat (limited to 'src/dto')
-rw-r--r--src/dto/AlarmDto.js27
-rw-r--r--src/dto/auth/AuthDto.js11
2 files changed, 28 insertions, 10 deletions
diff --git a/src/dto/AlarmDto.js b/src/dto/AlarmDto.js
new file mode 100644

index 0000000..281311d --- /dev/null +++ b/src/dto/AlarmDto.js
@@ -0,0 +1,27 @@ +import { SafeNSoundError } from '#util/error.js'; +import Joi from 'joi'; +import { AlarmType } from '#db/schemas/index.js'; + +/** + * Generic authentication DTO. + */ +export class AlarmDto { + static schema = new Joi.object({ + createdAt: Joi.date().optional(), + reason: Joi.string().valid(...Object.values(AlarmType)) + }); + + createdAt; + reason; + + static async create(data) { + const obj = new AlarmDto(); + for (const key of Object.keys(data)) { + if (key in obj) { + obj[key] = data[key]; + } + } + + return await AlarmDto.schema.validateAsync(obj); + } +} diff --git a/src/dto/auth/AuthDto.js b/src/dto/auth/AuthDto.js
index 22e2620..0a4c8dd 100644 --- a/src/dto/auth/AuthDto.js +++ b/src/dto/auth/AuthDto.js
@@ -23,15 +23,6 @@ export class AuthDto { } } - 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 - }); - } + return await AuthDto.schema.validateAsync(obj); } }