Restructuring the Project
Updating dependencies
This commit is contained in:
134
Backend/src/models/user.ts
Normal file
134
Backend/src/models/user.ts
Normal file
@ -0,0 +1,134 @@
|
||||
import DB from "../database";
|
||||
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model";
|
||||
import { ObjectID } from "mongodb";
|
||||
import { v4 } from "uuid";
|
||||
import { randomString } from "../helper/random";
|
||||
|
||||
export enum Gender {
|
||||
none,
|
||||
male,
|
||||
female,
|
||||
other,
|
||||
}
|
||||
|
||||
export interface IUser extends ModelDataBase {
|
||||
uid: string;
|
||||
username: string;
|
||||
|
||||
name: string;
|
||||
birthday?: Date;
|
||||
gender: Gender;
|
||||
admin: boolean;
|
||||
password: string;
|
||||
salt: string;
|
||||
mails: ObjectID[];
|
||||
phones: { phone: string; verified: boolean; primary: boolean }[];
|
||||
encryption_key: string;
|
||||
}
|
||||
|
||||
const User = DB.addModel<IUser>({
|
||||
name: "user",
|
||||
versions: [
|
||||
{
|
||||
migration: () => {},
|
||||
schema: {
|
||||
uid: { type: String, default: () => v4() },
|
||||
username: { type: String },
|
||||
name: { type: String },
|
||||
birthday: { type: Date, optional: true },
|
||||
gender: { type: Number },
|
||||
admin: { type: Boolean },
|
||||
password: { type: String },
|
||||
salt: { type: String },
|
||||
mails: { type: Array, default: () => [] },
|
||||
phones: {
|
||||
array: true,
|
||||
model: true,
|
||||
type: {
|
||||
phone: { type: String },
|
||||
verified: { type: Boolean },
|
||||
primary: { type: Boolean },
|
||||
},
|
||||
},
|
||||
twofactor: {
|
||||
array: true,
|
||||
model: true,
|
||||
type: {
|
||||
token: { type: String },
|
||||
valid: { type: Boolean },
|
||||
type: { type: Number },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
migration: (e: IUser) => {
|
||||
e.encryption_key = randomString(64);
|
||||
},
|
||||
schema: {
|
||||
uid: { type: String, default: () => v4() },
|
||||
username: { type: String },
|
||||
name: { type: String },
|
||||
birthday: { type: Date, optional: true },
|
||||
gender: { type: Number },
|
||||
admin: { type: Boolean },
|
||||
password: { type: String },
|
||||
salt: { type: String },
|
||||
mails: { type: Array, default: () => [] },
|
||||
phones: {
|
||||
array: true,
|
||||
model: true,
|
||||
type: {
|
||||
phone: { type: String },
|
||||
verified: { type: Boolean },
|
||||
primary: { type: Boolean },
|
||||
},
|
||||
},
|
||||
twofactor: {
|
||||
array: true,
|
||||
model: true,
|
||||
type: {
|
||||
token: { type: String },
|
||||
valid: { type: Boolean },
|
||||
type: { type: Number },
|
||||
},
|
||||
},
|
||||
encryption_key: {
|
||||
type: String,
|
||||
default: () => randomString(64),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
migration: (e: any) => {
|
||||
delete e.twofactor;
|
||||
},
|
||||
schema: {
|
||||
uid: { type: String, default: () => v4() },
|
||||
username: { type: String },
|
||||
name: { type: String },
|
||||
birthday: { type: Date, optional: true },
|
||||
gender: { type: Number },
|
||||
admin: { type: Boolean },
|
||||
password: { type: String },
|
||||
salt: { type: String },
|
||||
mails: { type: Array, default: () => [] },
|
||||
phones: {
|
||||
array: true,
|
||||
model: true,
|
||||
type: {
|
||||
phone: { type: String },
|
||||
verified: { type: Boolean },
|
||||
primary: { type: Boolean },
|
||||
},
|
||||
},
|
||||
encryption_key: {
|
||||
type: String,
|
||||
default: () => randomString(64),
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export default User;
|
||||
Reference in New Issue
Block a user