feat: team module added

This commit is contained in:
Mir Arif Hasan
2023-02-07 21:15:54 +06:00
parent 420359066e
commit 9bee62ada9
12 changed files with 1937 additions and 2 deletions

View 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>
}

View File

@@ -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: {