summary refs log tree commit diff
path: root/src/dto/AlarmDto.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/dto/AlarmDto.js')
-rw-r--r--src/dto/AlarmDto.js27
1 files changed, 27 insertions, 0 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); + } +}