Skip to content

Commit

Permalink
feat(image): add filter by keyword and category (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayocodingit authored Dec 5, 2023
1 parent 5e8e295 commit efa44f9
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/modules/images/repository/mongo/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@ import imageSchema from '../../../../database/mongo/schemas/image.schema'
class Repository {
constructor(private logger: Logger) {}

public async Fetch({ offset, limit }: RequestParams) {
const data = await imageSchema.find().skip(offset).limit(limit)
const count = await imageSchema.find().count()
public async Fetch({ offset, limit, keyword, category }: RequestParams) {
const filter = {}

if (keyword)
Object.assign(filter, {
title: {
$regex: new RegExp(keyword, 'i'),
},
})

if (category)
Object.assign(filter, {
category: category,
})

const data = await imageSchema.find(filter).skip(offset).limit(limit)
const count = await imageSchema.find(filter).count()

return {
data,
Expand Down

0 comments on commit efa44f9

Please sign in to comment.