Boilerplate generator and deno tasks for monorepo
This commit is contained in:
28
user-service/data.ts
Normal file
28
user-service/data.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import mongoose, { Schema, SchemaTypes } from 'mongoose';
|
||||
import * as bcrypt from "https://deno.land/x/bcrypt@v0.4.1/mod.ts";
|
||||
import { genSalt } from 'https://deno.land/x/bcrypt@v0.4.1/src/main.ts';
|
||||
import { configDatabase } from 'lib/data.ts';
|
||||
|
||||
configDatabase(mongoose, 'CGGUsers');
|
||||
|
||||
const userSchema = new Schema({
|
||||
username: {
|
||||
type: SchemaTypes.String,
|
||||
required: true,
|
||||
unique: true
|
||||
},
|
||||
password: {
|
||||
type: SchemaTypes.String,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
|
||||
userSchema.methods.generateHash = async (pw: string) => {
|
||||
|
||||
return await bcrypt.hash(pw, await genSalt(8));
|
||||
}
|
||||
userSchema.methods.validatePassword = async function(pw:string) {
|
||||
return await bcrypt.compare(pw, this.password)
|
||||
}
|
||||
|
||||
export const User = mongoose.model('User', userSchema);
|
Reference in New Issue
Block a user