Skip to content

Commit

Permalink
Merge pull request #31 from gsainfoteam/22-psw'
Browse files Browse the repository at this point in the history
fix: Group upsert
  • Loading branch information
siwonpada authored May 2, 2024
2 parents 5ee63cf + e51e123 commit 4f1a705
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/notice/notice.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export class NoticeRepository {
...(orderBy === 'deadline'
? { currentDeadline: { gte: dayjs().startOf('d').toDate() } }
: orderBy === 'hot'
? {
createdAt: {
gte: dayjs().startOf('d').subtract(7, 'd').toDate(),
},
}
: {}),
? {
createdAt: {
gte: dayjs().startOf('d').subtract(7, 'd').toDate(),
},
}
: {}),
...(search
? {
OR: [
Expand Down Expand Up @@ -92,12 +92,12 @@ export class NoticeRepository {
...(orderBy === 'deadline'
? { currentDeadline: { gte: dayjs().startOf('d').toDate() } }
: orderBy === 'hot'
? {
createdAt: {
gte: dayjs().startOf('d').subtract(7, 'd').toDate(),
},
}
: {}),
? {
createdAt: {
gte: dayjs().startOf('d').subtract(7, 'd').toDate(),
},
}
: {}),
deletedAt: null,
authorId: my === 'own' ? userUuid : undefined,
reminders:
Expand Down Expand Up @@ -296,6 +296,19 @@ export class NoticeRepository {
},
},
});

if (groupName !== undefined) {
await this.prismaService.group.upsert({
where: {
name: groupName,
},
update: {},
create: {
name: groupName,
},
});
}

return this.prismaService.notice
.create({
data: {
Expand Down Expand Up @@ -366,6 +379,7 @@ export class NoticeRepository {
.catch((error) => {
if (error instanceof PrismaClientKnownRequestError) {
if (error.code === 'P2025') {
console.log(error);
this.logger.debug(`User uuid not found`);
throw new NotFoundException(`User uuid not found`);
}
Expand Down

0 comments on commit 4f1a705

Please sign in to comment.