From 4e9d5aa3a402ab48d822c73d5ee39a8acc116c71 Mon Sep 17 00:00:00 2001 From: celesca Date: Thu, 7 Nov 2024 23:55:18 +0700 Subject: [PATCH] formatting the code --- src/controllers/skillController.ts | 108 ++++++++++++++--------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/src/controllers/skillController.ts b/src/controllers/skillController.ts index 3b5857b..137e390 100644 --- a/src/controllers/skillController.ts +++ b/src/controllers/skillController.ts @@ -3,69 +3,69 @@ import { prisma } from "../prisma"; // Prisma client export const skillController = new Elysia({ prefix: "/skill" }) - .post( - "/create", - async ({ body, error }) => { - const { skillName } = body; + .post( + "/create", + async ({ body, error }) => { + const { skillName } = body; - const existingSkill = await prisma.skills.findUnique({ - where: { Skill_Name: skillName }, - }); + const existingSkill = await prisma.skills.findUnique({ + where: { Skill_Name: skillName }, + }); - if (existingSkill) { - return error(409, "Skill already exists"); - } + if (existingSkill) { + return error(409, "Skill already exists"); + } - const newSkill = await prisma.skills.create({ - data: { - Skill_Name: skillName, + const newSkill = await prisma.skills.create({ + data: { + Skill_Name: skillName, + }, + }); + + return newSkill; }, - }); + { + body: t.Object({ + skillName: t.String(), + }), + } + ) - return newSkill; - }, - { - body: t.Object({ - skillName: t.String(), - }), - } - ) + // Add skill to user + .post( + "/add-to-user", + async ({ body, error }) => { + const { userID, skillName } = body; - // Add skill to user - .post( - "/add-to-user", - async ({ body, error }) => { - const { userID, skillName } = body; + const skill = await prisma.skills.findUnique({ + where: { Skill_Name: skillName }, + }); - const skill = await prisma.skills.findUnique({ - where: { Skill_Name: skillName }, - }); + if (!skill) { + return error(404, "Skill not found"); + } - if (!skill) { - return error(404, "Skill not found"); - } + const user = await prisma.user.findUnique({ + where: { UserID: userID }, + }); - const user = await prisma.user.findUnique({ - where: { UserID: userID }, - }); + if (!user) { + return error(404, "User not found"); + } - if (!user) { - return error(404, "User not found"); - } + const userSkill = await prisma.userSkills.create({ + data: { + UserID: userID, + Skill_ID: skill.Skill_ID, + }, + }); - const userSkill = await prisma.userSkills.create({ - data: { - UserID: userID, - Skill_ID: skill.Skill_ID, + return userSkill; }, - }); - - return userSkill; - }, - { - body: t.Object({ - userID: t.String(), - skillName: t.String(), - }), - } - ); \ No newline at end of file + { + body: t.Object({ + userID: t.String(), + skillName: t.String(), + }), + } + ); \ No newline at end of file