Skip to content

Commit

Permalink
Stashing WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dv297 committed Oct 21, 2022
1 parent 861d8ce commit 00d1797
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/pages/api/issue/search/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { NextApiRequest, NextApiResponse } from 'next';

import { withAuthMiddleware } from '@src/lib/withAuthMiddleware';
import IssueRepo from '@src/repos/IssueRepo';
import UserRepo from '@src/repos/UserRepo';
import routeMatcher from '@src/utils/routeMatcher';

const search = async (req: NextApiRequest, res: NextApiResponse) => {
const currentUser = await UserRepo.getCurrentUser({ req, res });

if (!currentUser) {
return;
}

const result = await IssueRepo.searchIssues('asdasd');

const response = { data: result };
return res.json(response);
};

async function handle(req: NextApiRequest, res: NextApiResponse) {
return routeMatcher(req, res, {
GET: search,
});
}

export default withAuthMiddleware(handle);
21 changes: 21 additions & 0 deletions src/repos/IssueRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ const IssueRepo = {
issue,
};
},
async searchIssues(queryString: string) {
return prisma.issue.findMany({
where: {
title: {
contains: queryString,
mode: 'insensitive',
},
},
select: {
id: true,
title: true,
workspaceIssueCount: true,
workspace: {
select: {
tag: true,
},
},
},
take: 5,
});
},
async updateIssueByProperty(
user: User,
issueTag: string,
Expand Down

0 comments on commit 00d1797

Please sign in to comment.