Boilerplate generator and deno tasks for monorepo

This commit is contained in:
Emma
2023-05-01 20:28:18 -06:00
parent a367562ba0
commit a910783882
36 changed files with 1164 additions and 47 deletions

28
user-service/data.ts Normal file
View 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);