forked from hypersign-protocol/entity-api-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from hypersign-protocol/hypersignAuth
added user module
- Loading branch information
Showing
9 changed files
with
87 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Logger } from '@nestjs/common'; | ||
import { User, UserDocument } from '../schema/user.schema'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { FilterQuery, Model } from 'mongoose'; | ||
|
||
export class UserRepository { | ||
constructor( | ||
@InjectModel(User.name) private readonly userModel: Model<UserDocument>, | ||
) {} | ||
async findOne(userFilterQuery: FilterQuery<User>): Promise<User> { | ||
Logger.log( | ||
'findOne() method: starts, finding particular user from db', | ||
'UserRepository', | ||
); | ||
return this.userModel.findOne(userFilterQuery); | ||
} | ||
|
||
async create(user: User): Promise<UserDocument> { | ||
Logger.log( | ||
'create() method: starts, adding user to userDb', | ||
'UserRepository', | ||
); | ||
const newUser = new this.userModel(user); | ||
return newUser.save(); | ||
} | ||
|
||
async findOneUpdate( | ||
userFilterQuery: FilterQuery<UserDocument>, | ||
user: Partial<UserDocument>, | ||
) { | ||
Logger.log( | ||
'findOneUpdate() method: start, updating user db', | ||
'UserRepository', | ||
); | ||
return this.userModel.findOneAndUpdate(userFilterQuery, user, { | ||
new: true, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||
|
||
export type UserDocument = User & Document; | ||
@Schema({ timestamps: true }) | ||
export class User { | ||
@Prop({ required: true }) | ||
userId: string; | ||
@Prop({ required: true, unique: true }) | ||
email: string; | ||
@Prop({ required: true, unique: true }) | ||
did: string; | ||
} | ||
|
||
export const UserSchema = SchemaFactory.createForClass(User); | ||
UserSchema.index({ email: 1 }, { unique: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters