Skip to content

Commit

Permalink
Merge pull request #17 from azuya/main
Browse files Browse the repository at this point in the history
Contact List
  • Loading branch information
nizarfadlan authored Sep 24, 2024
2 parents 0fc1f37 + 6fbdc82 commit bca04d0
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/controllers/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,43 @@ import { logger } from "@/utils";
import { makePhotoURLHandler } from "./misc";
import { prisma } from "@/config/database";
import WhatsappService from "@/whatsapp/service";
import { Prisma } from "@prisma/client";

Check failure on line 6 in src/controllers/contact.ts

View workflow job for this annotation

GitHub Actions / release (18.x)

All imports in the declaration are only used as types. Use `import type`

export const list: RequestHandler = async (req, res) => {
try {
const { sessionId } = req.params;
const { cursor = undefined, limit = 25, search } = req.query;
// Create whereConditions
const whereConditions: Prisma.ContactWhereInput = {
id: { endsWith: "s.whatsapp.net" },
sessionId,
};
// Add OR condition if only search parameter is exist
if (search) {
whereConditions.OR = [
{
name: {
contains: String(search),
},
},
{
verifiedName: {
contains: String(search),
},
},
{
notify: {
contains: String(search),
},
},
];
}
const contacts = await prisma.contact.findMany({
cursor: cursor ? { pkId: Number(cursor) } : undefined,
take: Number(limit),
skip: cursor ? 1 : 0,
where: {
id: { endsWith: "s.whatsapp.net" },
sessionId,
OR: [
{
name: {
contains: String(search),
},
},
{
verifiedName: {
contains: String(search),
},
},
{
notify: {
contains: String(search),
},
},
],
},
where: whereConditions,
});

res.status(200).json({
data: contacts,
cursor:
Expand All @@ -43,7 +48,7 @@ export const list: RequestHandler = async (req, res) => {
: null,
});
} catch (e) {
const message = "An error occured during contact list";
const message = "An error occurred during contact list";
logger.error(e, message);
res.status(500).json({ error: message });
}
Expand Down

0 comments on commit bca04d0

Please sign in to comment.