Files
HKSingleParty/03_source/cms_backend/src/app/services/party-event.service.ts

140 lines
3.7 KiB
TypeScript

// src/app/services/party-event.service.ts
//
// PURPOSE:
// - Service for handling EventItem (PartyEvent) Record
//
import type { EventItem } from '@prisma/client';
import prisma from '../lib/prisma';
type CreateEvent = {
name: string;
title: string;
eventDate: Date;
location: string;
duration_m: number;
ageBottom?: number;
ageTop?: number;
currency?: string;
price?: number;
priceSale?: number;
coverUrl?: string;
images?: string[];
description?: string;
subDescription?: string;
publish?: string;
category?: string;
tags?: string[];
joinMembers?: any[];
};
type UpdateEvent = {
name?: string;
title?: string;
eventDate?: Date;
location?: string;
duration_m?: number;
ageBottom?: number;
ageTop?: number;
currency?: string;
price?: number;
priceSale?: number;
coverUrl?: string;
images?: string[];
description?: string;
subDescription?: string;
publish?: string;
category?: string;
tags?: string[];
joinMembers?: any[];
};
async function listEvents(): Promise<EventItem[]> {
return prisma.eventItem.findMany({
include: { reviews: true },
});
}
async function getEvent(eventId: string): Promise<EventItem | null> {
return prisma.eventItem.findUnique({
where: { id: eventId },
include: { reviews: true },
});
}
async function getEventByNameOrTitle(searchText: string): Promise<EventItem[] | null> {
return prisma.eventItem.findMany({
where: {
OR: [{ name: { contains: searchText, mode: 'insensitive' } }, { title: { contains: searchText, mode: 'insensitive' } }],
},
include: { reviews: true },
});
}
async function createEvent(eventData: any) {
return await prisma.eventItem.create({ data: eventData });
}
async function updateEvent(eventId: string, updateForm: any) {
return prisma.eventItem.update({
where: { id: eventId },
data: {
available: updateForm.available,
category: updateForm.category,
code: updateForm.code,
colors: updateForm.colors,
coverUrl: updateForm.coverUrl,
description: updateForm.description,
gender: updateForm.gender,
images: updateForm.images,
inventoryType: updateForm.inventoryType,
name: updateForm.name,
newLabel: updateForm.newLabel,
price: updateForm.price,
priceSale: updateForm.priceSale,
publish: updateForm.publish,
quantity: updateForm.quantity,
ratings: updateForm.ratings,
saleLabel: updateForm.saleLabel,
sizes: updateForm.sizes,
sku: updateForm.sku,
subDescription: updateForm.subDescription,
tags: updateForm.tags,
taxes: updateForm.taxes,
totalRatings: updateForm.totalRatings,
totalReviews: updateForm.totalReviews,
totalSold: updateForm.totalSold,
//
ageBottom: updateForm.ageBottom,
ageTop: updateForm.ageTop,
avatar: updateForm.avatar,
currency: updateForm.currency,
capacity: updateForm.capacity,
duration_m: updateForm.duration_m,
endDate: updateForm.endDate,
eventDate: updateForm.eventDate,
isFeatured: updateForm.isFeatured,
joinMembers: updateForm.joinMembers,
location: updateForm.location,
organizer: updateForm.organizer,
registrationDeadline: updateForm.registrationDeadline,
requirements: updateForm.requirements,
schedule: updateForm.schedule,
speakers: updateForm.speakers,
sponsors: updateForm.sponsors,
startDate: updateForm.startDate,
status: updateForm.status,
title: updateForm.title,
},
});
}
async function deleteEvent(eventId: string) {
return prisma.eventItem.delete({
where: { id: eventId },
});
}
export { getEvent, listEvents, createEvent, updateEvent, deleteEvent, getEventByNameOrTitle, type CreateEvent, type UpdateEvent };