Skip to content

Commit

Permalink
Dto compatibility fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DankaMarci committed May 26, 2024
1 parent a40bda9 commit fe719bf
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions apps/backend/src/event/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import { UpdateEventDto } from './dto/update-event.dto';
export class EventService {
constructor(private readonly prisma: PrismaService) {}

/*async create(data: CreateEventDto): Promise<Event> {
return await this.prisma.event.create({ data });
}*/

async create(data: CreateEventDto): Promise<Event> {
return await this.prisma.event.create({ data });
const { category, ownerUser, ownerGroup, ...rest } = data;
return await this.prisma.event.create({
data: {
...rest,
category: { connect: { id: category.id } },
ownerUser: { connect: { id: ownerUser.id } },
ownerGroup: { connect: { id: ownerGroup.id } },
},
});
}

async findAll(): Promise<Event[]> {
Expand All @@ -33,7 +37,16 @@ export class EventService {

async update(id: number, data: UpdateEventDto): Promise<Event> {
try {
return await this.prisma.event.update({ where: { id: id }, data: data });
const { category, ownerUser, ownerGroup, ...rest } = data;
return await this.prisma.event.update({
where: { id: id },
data: {
...rest,
category: { connect: { id: category.id } },
ownerUser: { connect: { id: ownerUser.id } },
ownerGroup: { connect: { id: ownerGroup.id } },
},
});
} catch (e) {
throw new NotFoundException(`Event with ID ${id} not found`);
}
Expand Down

0 comments on commit fe719bf

Please sign in to comment.