🚚 create backup folder
create backup folder for archive the old modules
This commit is contained in:
@ -0,0 +1,31 @@
|
||||
import {
|
||||
returnErrorResponse,
|
||||
returnWriteResponse,
|
||||
} from "../../../helpers/callback/httpResponse";
|
||||
import { Context } from "elysia";
|
||||
import { assignRoleToUserSchema } from "../schemas/assignRoleToUser.schema";
|
||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||
import { assignRoleToUserService } from "../services/assignRoleToUser.service";
|
||||
|
||||
export const assignRoleToUserController = async (ctx: Context) => {
|
||||
const validation = assignRoleToUserSchema.safeParse(ctx.body);
|
||||
if (!validation.success)
|
||||
return returnErrorResponse(
|
||||
ctx.set,
|
||||
400,
|
||||
"Invalid Request",
|
||||
validation.error
|
||||
);
|
||||
|
||||
try {
|
||||
const assignRoleToUser = await assignRoleToUserService(validation.data);
|
||||
return returnWriteResponse(
|
||||
ctx.set,
|
||||
201,
|
||||
"User Role Assigned Successfully",
|
||||
assignRoleToUser
|
||||
);
|
||||
} catch (error) {
|
||||
return mainErrorHandler(ctx.set, error);
|
||||
}
|
||||
};
|
||||
6
backup/modules/userRoleAssignment/index.ts
Normal file
6
backup/modules/userRoleAssignment/index.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import Elysia from "elysia";
|
||||
import { assignRoleToUserController } from "./controller/assignRoleToUser.controller";
|
||||
|
||||
export const userRoleAssignmentModule = new Elysia({
|
||||
prefix: "/role-assignments",
|
||||
}).post("/assign", assignRoleToUserController);
|
||||
@ -0,0 +1,16 @@
|
||||
import { userRoleAssignmentModel } from "../userRoleAssignment.model";
|
||||
import { InputUserRoleAssignment } from "../userRoleAssignment.types";
|
||||
|
||||
export const assignRoleToUserRepository = async ({
|
||||
userId,
|
||||
roleId,
|
||||
}: InputUserRoleAssignment) => {
|
||||
const assignRoleToUser = await userRoleAssignmentModel.create({
|
||||
data: {
|
||||
userId,
|
||||
roleId,
|
||||
},
|
||||
});
|
||||
|
||||
return assignRoleToUser;
|
||||
};
|
||||
@ -0,0 +1,6 @@
|
||||
import z from "zod";
|
||||
|
||||
export const assignRoleToUserSchema = z.object({
|
||||
userId: z.string(),
|
||||
roleId: z.string(),
|
||||
});
|
||||
@ -0,0 +1,14 @@
|
||||
import { assignRoleToUserRepository } from "../repositories/assignRoleToUser.repository";
|
||||
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||
import { InputUserRoleAssignment } from "../userRoleAssignment.types";
|
||||
|
||||
export const assignRoleToUserService = async (
|
||||
payload: InputUserRoleAssignment
|
||||
) => {
|
||||
try {
|
||||
const assignRoleToUser = await assignRoleToUserRepository(payload);
|
||||
return assignRoleToUser;
|
||||
} catch (error) {
|
||||
ErrorForwarder(error);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,3 @@
|
||||
import { prisma } from "../../utils/databases/prisma/connection";
|
||||
|
||||
export const userRoleAssignmentModel = prisma.userRoleAssignment;
|
||||
@ -0,0 +1,4 @@
|
||||
export interface InputUserRoleAssignment {
|
||||
userId: string;
|
||||
roleId: string;
|
||||
}
|
||||
Reference in New Issue
Block a user