"feat: update service implementations with new features and structural changes"
This commit is contained in:
@@ -16,6 +16,7 @@ import prisma from '../lib/prisma';
|
|||||||
type CreateAppLog = {
|
type CreateAppLog = {
|
||||||
level: number;
|
level: number;
|
||||||
message: string;
|
message: string;
|
||||||
|
metadata: Record<string, any>;
|
||||||
};
|
};
|
||||||
|
|
||||||
// type UpdateAppLog = {
|
// type UpdateAppLog = {
|
||||||
@@ -31,6 +32,10 @@ async function getAppLog(appLogId: string) {
|
|||||||
return prisma.appLog.findFirst({ where: { id: appLogId } });
|
return prisma.appLog.findFirst({ where: { id: appLogId } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createAppLog(level: number, message: string, metadata: Record<string, any>) {
|
||||||
|
return prisma.appLog.create({ data: { level, message, metadata } });
|
||||||
|
}
|
||||||
|
|
||||||
async function createNewAppLog(createForm: CreateAppLog) {
|
async function createNewAppLog(createForm: CreateAppLog) {
|
||||||
return prisma.appLog.create({ data: createForm });
|
return prisma.appLog.create({ data: createForm });
|
||||||
}
|
}
|
||||||
@@ -48,5 +53,6 @@ export {
|
|||||||
listAppLogs,
|
listAppLogs,
|
||||||
// updateAppLog,
|
// updateAppLog,
|
||||||
deleteAppLog,
|
deleteAppLog,
|
||||||
|
createAppLog,
|
||||||
createNewAppLog,
|
createNewAppLog,
|
||||||
};
|
};
|
||||||
|
@@ -7,10 +7,6 @@
|
|||||||
// - Follows same pattern as helloworld.service.ts
|
// - Follows same pattern as helloworld.service.ts
|
||||||
//
|
//
|
||||||
|
|
||||||
import type { Event } from '@prisma/client';
|
|
||||||
|
|
||||||
import prisma from '../lib/prisma';
|
|
||||||
|
|
||||||
type CreateEvent = {
|
type CreateEvent = {
|
||||||
eventDate: DateTime;
|
eventDate: DateTime;
|
||||||
title: string;
|
title: string;
|
||||||
@@ -39,27 +35,33 @@ type UpdateEvent = {
|
|||||||
memberId?: number;
|
memberId?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function listEvents(): Promise<Event[]> {
|
// async function listEvents(): Promise<Event[]> {
|
||||||
return prisma.event.findMany();
|
// return prisma.event.findMany();
|
||||||
}
|
// }
|
||||||
|
|
||||||
async function getEvent(eventId: number) {
|
// async function getEvent(eventId: number) {
|
||||||
return prisma.event.findFirst({ where: { id: eventId } });
|
// return prisma.event.findFirst({ where: { id: eventId } });
|
||||||
}
|
// }
|
||||||
|
|
||||||
async function createNewEvent(createForm: CreateEvent) {
|
// async function createNewEvent(createForm: CreateEvent) {
|
||||||
return prisma.event.create({ data: createForm });
|
// return prisma.event.create({ data: createForm });
|
||||||
}
|
// }
|
||||||
|
|
||||||
async function updateEvent(eventId: number, updateForm: UpdateEvent) {
|
// async function updateEvent(eventId: number, updateForm: UpdateEvent) {
|
||||||
return prisma.event.update({
|
// return prisma.event.update({
|
||||||
where: { id: eventId },
|
// where: { id: eventId },
|
||||||
data: updateForm,
|
// data: updateForm,
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
async function deleteEvent(eventId: number) {
|
// async function deleteEvent(eventId: number) {
|
||||||
return prisma.event.delete({ where: { id: eventId } });
|
// return prisma.event.delete({ where: { id: eventId } });
|
||||||
}
|
// }
|
||||||
|
|
||||||
export { getEvent, listEvents, updateEvent, deleteEvent, createNewEvent };
|
export {
|
||||||
|
listEvents,
|
||||||
|
// getEvent,
|
||||||
|
// updateEvent,
|
||||||
|
// deleteEvent,
|
||||||
|
// createNewEvent,
|
||||||
|
};
|
||||||
|
71
03_source/cms_backend/src/app/services/eventItem.service.ts
Normal file
71
03_source/cms_backend/src/app/services/eventItem.service.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
// src/app/services/event.service.ts
|
||||||
|
//
|
||||||
|
// PURPOSE:
|
||||||
|
// - Service for handling Event records
|
||||||
|
//
|
||||||
|
// RULES:
|
||||||
|
// - Follows same pattern as helloworld.service.ts
|
||||||
|
//
|
||||||
|
|
||||||
|
import type { EventItem } from '@prisma/client';
|
||||||
|
|
||||||
|
import prisma from '../lib/prisma';
|
||||||
|
|
||||||
|
type CreateEvent = {
|
||||||
|
eventDate: DateTime;
|
||||||
|
title: string;
|
||||||
|
joinMembers?: Json[];
|
||||||
|
price: number;
|
||||||
|
currency: string;
|
||||||
|
duration_m: number;
|
||||||
|
ageBottom: number;
|
||||||
|
ageTop: number;
|
||||||
|
location: string;
|
||||||
|
avatar?: string;
|
||||||
|
memberId?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type UpdateEvent = {
|
||||||
|
eventDate?: DateTime;
|
||||||
|
title?: string;
|
||||||
|
joinMembers?: Json[];
|
||||||
|
price?: number;
|
||||||
|
currency?: string;
|
||||||
|
duration_m?: number;
|
||||||
|
ageBottom?: number;
|
||||||
|
ageTop?: number;
|
||||||
|
location?: string;
|
||||||
|
avatar?: string;
|
||||||
|
memberId?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
async function listEvents(): Promise<EventItem[]> {
|
||||||
|
return prisma.eventItem.findMany();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getEvent(eventId: string): Promise<EventItem | null> {
|
||||||
|
return prisma.eventItem.findFirst({ where: { id: eventId } });
|
||||||
|
}
|
||||||
|
|
||||||
|
// async function createNewEvent(createForm: CreateEvent) {
|
||||||
|
// return prisma.event.create({ data: createForm });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async function updateEvent(eventId: number, updateForm: UpdateEvent) {
|
||||||
|
// return prisma.event.update({
|
||||||
|
// where: { id: eventId },
|
||||||
|
// data: updateForm,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async function deleteEvent(eventId: number) {
|
||||||
|
// return prisma.event.delete({ where: { id: eventId } });
|
||||||
|
// }
|
||||||
|
|
||||||
|
export {
|
||||||
|
getEvent,
|
||||||
|
listEvents,
|
||||||
|
// updateEvent,
|
||||||
|
// deleteEvent,
|
||||||
|
// createNewEvent,
|
||||||
|
};
|
@@ -68,7 +68,7 @@ async function listProducts(): Promise<ProductItem[]> {
|
|||||||
return prisma.productItem.findMany();
|
return prisma.productItem.findMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getProduct(productId: string) {
|
async function getProduct(productId: string): Promise<ProductItem | null> {
|
||||||
return prisma.productItem.findUnique({ where: { id: productId } });
|
return prisma.productItem.findUnique({ where: { id: productId } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
127
03_source/cms_backend/src/app/services/user.service.ts
Normal file
127
03_source/cms_backend/src/app/services/user.service.ts
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
// src/app/services/user.service.ts
|
||||||
|
//
|
||||||
|
// PURPOSE:
|
||||||
|
// - Handle User Record CRUD operations
|
||||||
|
//
|
||||||
|
// RULES:
|
||||||
|
// - Follow Prisma best practices for database operations
|
||||||
|
// - Validate input data before processing
|
||||||
|
//
|
||||||
|
|
||||||
|
import type { User } from '@prisma/client';
|
||||||
|
|
||||||
|
import prisma from '../lib/prisma';
|
||||||
|
|
||||||
|
type CreateUser = {
|
||||||
|
email: string;
|
||||||
|
// name?: string;
|
||||||
|
// password: string;
|
||||||
|
// role?: Role;
|
||||||
|
// isEmailVerified?: boolean;
|
||||||
|
// admin?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type UpdateUser = {
|
||||||
|
email?: string;
|
||||||
|
// name?: string;
|
||||||
|
// password?: string;
|
||||||
|
// role?: Role;
|
||||||
|
// isEmailVerified?: boolean;
|
||||||
|
isAdmin?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
// async function listUsers(): Promise<UserItem[]> {
|
||||||
|
// return prisma.userItem.findMany();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async function getUserItem(userId: string): Promise<UserItem | null> {
|
||||||
|
// return prisma.userItem.findFirst({ where: { id: userId } });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async function updateUser(userId: string, updateForm: UpdateUser): Promise<User> {
|
||||||
|
// return prisma.userItem.update({
|
||||||
|
// where: { id: userId },
|
||||||
|
// data: updateForm,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // check if userId is a admin
|
||||||
|
// // check if userId is a admin
|
||||||
|
// async function isAdmin(userId: string): Promise<boolean> {
|
||||||
|
// const user = await getUserItem(userId);
|
||||||
|
// return user?.isAdmin === true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async function changeToAdmin(userIdToPromote: string, userIdOfApplicant: string) {
|
||||||
|
// // check the applicant is admin or not
|
||||||
|
// const userApplicant = await getUserItem(userIdOfApplicant);
|
||||||
|
// let promoteResult = {};
|
||||||
|
|
||||||
|
// if (userApplicant && userApplicant.isAdmin) {
|
||||||
|
// // applicant is an admin
|
||||||
|
// promoteResult = await updateUser(userIdToPromote, { isAdmin: true });
|
||||||
|
// } else {
|
||||||
|
// promoteResult = { status: 'failed', message: 'applicant is not a admin' };
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return promoteResult;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async function changeToUser(userIdToPromote: string, userIdOfApplicant: string) {
|
||||||
|
// // check the applicant is admin or not
|
||||||
|
// const userApplicant = await getUserItem(userIdOfApplicant);
|
||||||
|
// let promoteResult = {};
|
||||||
|
|
||||||
|
// if (userApplicant && userApplicant.isAdmin) {
|
||||||
|
// // applicant is an admin
|
||||||
|
// promoteResult = await updateUser(userIdToPromote, { isAdmin: false });
|
||||||
|
// } else {
|
||||||
|
// promoteResult = { status: 'failed', message: 'applicant is not a admin' };
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return promoteResult;
|
||||||
|
// }
|
||||||
|
|
||||||
|
async function getUserById(id: string): Promise<User | null> {
|
||||||
|
return prisma.user.findFirst({ where: { id } });
|
||||||
|
}
|
||||||
|
|
||||||
|
// async function getUserByEmail(email: string): Promise<void> {
|
||||||
|
// // return prisma.userItem.findUnique({
|
||||||
|
// // where: { email },
|
||||||
|
// // include: {
|
||||||
|
// // Token: true,
|
||||||
|
// // },
|
||||||
|
// // });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async function createNewUser(createForm: CreateUser): Promise<void> {
|
||||||
|
// // return prisma.userItem.create({
|
||||||
|
// // data: {
|
||||||
|
// // email: createForm.email,
|
||||||
|
// // name: createForm.name,
|
||||||
|
// // password: createForm.password,
|
||||||
|
// // role: createForm.role || 'USER',
|
||||||
|
// // isEmailVerified: createForm.isEmailVerified || false,
|
||||||
|
// // },
|
||||||
|
// // });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async function deleteUser(userId: number): Promise<void> {
|
||||||
|
// // return prisma.userItem.delete({ where: { id: userId } });
|
||||||
|
// }
|
||||||
|
|
||||||
|
export {
|
||||||
|
// getUser,
|
||||||
|
getUserById,
|
||||||
|
// isAdmin,
|
||||||
|
// listUsers,
|
||||||
|
// updateUser,
|
||||||
|
// deleteUser,
|
||||||
|
// changeToUser,
|
||||||
|
// createNewUser,
|
||||||
|
// changeToAdmin,
|
||||||
|
// getUserByEmail,
|
||||||
|
// type CreateUser,
|
||||||
|
// type UpdateUser,
|
||||||
|
};
|
@@ -82,6 +82,10 @@ async function changeToUser(userIdToPromote: string, userIdOfApplicant: string)
|
|||||||
return promoteResult;
|
return promoteResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getUserById1(id: string): Promise<UserItem | null> {
|
||||||
|
return prisma.userItem.findFirst({ where: { id } });
|
||||||
|
}
|
||||||
|
|
||||||
async function getUserByEmail(email: string): Promise<void> {
|
async function getUserByEmail(email: string): Promise<void> {
|
||||||
// return prisma.userItem.findUnique({
|
// return prisma.userItem.findUnique({
|
||||||
// where: { email },
|
// where: { email },
|
||||||
@@ -113,6 +117,7 @@ export {
|
|||||||
listUsers,
|
listUsers,
|
||||||
updateUser,
|
updateUser,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
|
getUserById,
|
||||||
changeToUser,
|
changeToUser,
|
||||||
createNewUser,
|
createNewUser,
|
||||||
changeToAdmin,
|
changeToAdmin,
|
||||||
|
Reference in New Issue
Block a user