summary refs log tree commit diff
path: root/src/db/schemas/user.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/schemas/user.js')
-rw-r--r--src/db/schemas/user.js29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/db/schemas/user.js b/src/db/schemas/user.js

index f490966..063fddf 100644 --- a/src/db/schemas/user.js +++ b/src/db/schemas/user.js
@@ -1,6 +1,17 @@ import { model, Schema } from 'mongoose'; import { hash, compare } from 'bcrypt'; +export const UserType = Object.freeze({ + USER: 'user', + MONITOR: 'monitor', + ADMIN: 'admin' +}); + +export const AlarmType = Object.freeze({ + FALL: 'fall', + TOILET: 'toilet' +}); + export const deviceSchema = new Schema({ name: { type: String, @@ -19,6 +30,19 @@ export const deviceSchema = new Schema({ } }); +export const alarmSchema = new Schema({ + createdAt: { + type: Date, + default: Date.now, + immutable: true + }, + reason: { + type: String, + enum: Object.values(AlarmType), + required: true + } +}); + /** * User schema for MongoDB. * @type {module:mongoose.Schema} @@ -42,7 +66,7 @@ export const userSchema = new Schema({ }, type: { type: String, - enum: ['user', 'monitor', 'admin'], + enum: Object.values(UserType), default: 'user' }, createdAt: { @@ -53,6 +77,9 @@ export const userSchema = new Schema({ devices: { type: [deviceSchema], default: [] + }, + alarm: { + type: alarmSchema } });