feat: team module added
This commit is contained in:
11
packages/hoppscotch-backend/src/user/user.data.handler.ts
Normal file
11
packages/hoppscotch-backend/src/user/user.data.handler.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import * as T from "fp-ts/Task"
|
||||
import * as TO from "fp-ts/TaskOption"
|
||||
import { User } from "src/user/user.model"
|
||||
|
||||
/**
|
||||
* Defines how external services should handle User Data and User data related operations and actions.
|
||||
*/
|
||||
export interface UserDataHandler {
|
||||
canAllowUserDeletion: (user: User) => TO.TaskOption<string>
|
||||
onUserDelete: (user: User) => T.Task<void>
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { SessionType, User } from './user.model';
|
||||
import { USER_UPDATE_FAILED } from 'src/errors';
|
||||
import { PubSubService } from 'src/pubsub/pubsub.service';
|
||||
import { stringToJson } from 'src/utils';
|
||||
import { UserDataHandler } from './user.data.handler';
|
||||
|
||||
@Injectable()
|
||||
export class UserService {
|
||||
@@ -16,13 +17,19 @@ export class UserService {
|
||||
private readonly pubsub: PubSubService,
|
||||
) {}
|
||||
|
||||
private userDataHandlers: UserDataHandler[] = [];
|
||||
|
||||
registerUserDataHandler(handler: UserDataHandler) {
|
||||
this.userDataHandlers.push(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find User with given email id
|
||||
*
|
||||
* @param email User's email
|
||||
* @returns Option of found User
|
||||
*/
|
||||
async findUserByEmail(email: string) {
|
||||
async findUserByEmail(email: string): Promise<O.None | O.Some<AuthUser>> {
|
||||
try {
|
||||
const user = await this.prisma.user.findUniqueOrThrow({
|
||||
where: {
|
||||
@@ -41,7 +48,7 @@ export class UserService {
|
||||
* @param userUid User ID
|
||||
* @returns Option of found User
|
||||
*/
|
||||
async findUserById(userUid: string) {
|
||||
async findUserById(userUid: string): Promise<O.None | O.Some<AuthUser>> {
|
||||
try {
|
||||
const user = await this.prisma.user.findUniqueOrThrow({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user