Skip to content

Commit

Permalink
chore(be): make contest search case insensitive (#2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
1jiwoo27 authored Feb 10, 2025
1 parent 1e7c6df commit ed3ab15
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('ContestService', () => {
expect(contests.finished[0]).to.have.property('isRegistered')
})

it("shold return contests whose title contains '신입생'", async () => {
it("should return contests whose title contains '신입생'", async () => {
const keyword = '신입생'
const contests = await service.getContests(user01Id, keyword)

Expand Down
17 changes: 8 additions & 9 deletions apps/backend/apps/client/src/contest/contest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export class ContestService {
async getContests(userId?: number, search?: string) {
// 1. get all contests
const now = new Date()

const searchFilter = search
? { title: { contains: search, mode: Prisma.QueryMode.insensitive } }
: {}

const ongoingContests = await this.prisma.contest.findMany({
where: {
startTime: {
Expand All @@ -69,9 +74,7 @@ export class ContestService {
endTime: {
gt: now
},
title: {
contains: search
}
...searchFilter
},
orderBy: [{ startTime: 'asc' }, { endTime: 'asc' }],
select: contestSelectOption
Expand All @@ -82,9 +85,7 @@ export class ContestService {
startTime: {
gt: now
},
title: {
contains: search
}
...searchFilter
},
orderBy: [{ startTime: 'asc' }, { endTime: 'asc' }],
select: contestSelectOption
Expand All @@ -95,9 +96,7 @@ export class ContestService {
endTime: {
lte: now
},
title: {
contains: search
}
...searchFilter
},
orderBy: [{ startTime: 'asc' }, { endTime: 'asc' }],
select: contestSelectOption
Expand Down

0 comments on commit ed3ab15

Please sign in to comment.