Download api/src/model/user.ts from Jessedbrown/warran: direct link, hf CLI and curl.
- Browser
- Download file 988 Bytes
-
https://huggingface.co/Jessedbrown/warran/resolve/main/api/src/model/user.ts
- Command line
-
hf download hf://Jessedbrown/warran/api/src/model/user.ts
-
curl -L -o user.ts https://huggingface.co/Jessedbrown/warran/resolve/main/api/src/model/user.ts
988 Bytes
| import mongoose, { Schema, Document } from 'mongoose'; | |
| import { Encrypter } from '../service/encrypter'; | |
| export const UserSchema: Schema = new Schema({ | |
| email : { | |
| type: String, | |
| unique: true, | |
| required: 'Email required', | |
| lowercase: true, | |
| }, | |
| name: { | |
| type: String, | |
| required: 'Name required', | |
| lowercase: true, | |
| }, | |
| password: { | |
| type: String, | |
| required: 'Password required', | |
| }, | |
| balance: { | |
| type: Number, | |
| lowercase: true, | |
| default: 0, | |
| required: 'Balance required', | |
| }, | |
| }); | |
| export interface UserInputDTO { | |
| password: string; | |
| email: string; | |
| name: string; | |
| balance?: number; | |
| } | |
| export interface LoginInputDTO { | |
| email: string; | |
| password: string; | |
| } | |
| UserSchema.pre<UserInputDTO & Document>('save', async function (next) { | |
| const encrypter = new Encrypter(); | |
| const hashPassword = await encrypter.hash(this.password); | |
| this.password = hashPassword; | |
| next(); | |
| }); | |
| export const UserModel = mongoose.model('users', UserSchema); | |