This commit is contained in:
KMKoushik
2024-09-05 09:21:11 +10:00
parent 259937c60c
commit 7e1a63e048
2 changed files with 80 additions and 80 deletions

View File

@@ -5,49 +5,49 @@ import { deleteContact } from "~/server/service/contact-service";
import { getContactBook } from "../../api-utils"; import { getContactBook } from "../../api-utils";
const route = createRoute({ const route = createRoute({
method: "delete", method: "delete",
path: "/v1/contactBooks/{contactBookId}/contacts/{contactId}", path: "/v1/contactBooks/{contactBookId}/contacts/{contactId}",
request: { request: {
params: z.object({ params: z.object({
contactBookId: z.string().openapi({ contactBookId: z.string().openapi({
param: { param: {
name: "contactBookId", name: "contactBookId",
in: "path", in: "path",
},
example: "cuiwqdj74rygf74",
}),
contactId: z.string().openapi({
param: {
name: "contactId",
in: "path",
},
example: "cuiwqdj74rygf74",
}),
}),
},
responses: {
200: {
content: {
"application/json": {
schema: z.object({ success: z.boolean() }),
},
},
description: "Contact deleted successfully",
}, },
example: "cuiwqdj74rygf74",
}),
contactId: z.string().openapi({
param: {
name: "contactId",
in: "path",
},
example: "cuiwqdj74rygf74",
}),
}),
},
responses: {
200: {
content: {
"application/json": {
schema: z.object({ success: z.boolean() }),
},
},
description: "Contact deleted successfully",
}, },
},
}); });
function deleteContactHandler(app: PublicAPIApp) { function deleteContactHandler(app: PublicAPIApp) {
app.openapi(route, async (c) => { app.openapi(route, async (c) => {
const team = await getTeamFromToken(c); const team = await getTeamFromToken(c);
await getContactBook(c, team.id); await getContactBook(c, team.id);
const contactId = c.req.param("contactId"); const contactId = c.req.param("contactId");
await deleteContact(contactId); await deleteContact(contactId);
return c.json({ success: true }); return c.json({ success: true });
}); });
} }
export default deleteContactHandler; export default deleteContactHandler;

View File

@@ -5,61 +5,61 @@ import { addOrUpdateContact } from "~/server/service/contact-service";
import { getContactBook } from "../../api-utils"; import { getContactBook } from "../../api-utils";
const route = createRoute({ const route = createRoute({
method: "put", method: "put",
path: "/v1/contactBooks/{contactBookId}/contacts/{contactId}", path: "/v1/contactBooks/{contactBookId}/contacts/{contactId}",
request: { request: {
params: z.object({ params: z.object({
contactBookId: z contactBookId: z
.string() .string()
.min(3) .min(3)
.openapi({ .openapi({
param: { param: {
name: "contactBookId", name: "contactBookId",
in: "path", in: "path",
}, },
example: "cuiwqdj74rygf74", example: "cuiwqdj74rygf74",
}),
}), }),
body: { }),
required: true, body: {
content: { required: true,
"application/json": { content: {
schema: z.object({ "application/json": {
email: z.string(), schema: z.object({
firstName: z.string().optional(), email: z.string(),
lastName: z.string().optional(), firstName: z.string().optional(),
properties: z.record(z.string()).optional(), lastName: z.string().optional(),
subscribed: z.boolean().optional(), properties: z.record(z.string()).optional(),
}), subscribed: z.boolean().optional(),
}, }),
},
}, },
},
}, },
responses: { },
200: { responses: {
content: { 200: {
"application/json": { content: {
schema: z.object({ contactId: z.string() }), "application/json": {
}, schema: z.object({ contactId: z.string() }),
},
description: "Contact upserted successfully",
}, },
},
description: "Contact upserted successfully",
}, },
},
}); });
function upsertContact(app: PublicAPIApp) { function upsertContact(app: PublicAPIApp) {
app.openapi(route, async (c) => { app.openapi(route, async (c) => {
const team = await getTeamFromToken(c); const team = await getTeamFromToken(c);
const contactBook = await getContactBook(c, team.id); const contactBook = await getContactBook(c, team.id);
const contact = await addOrUpdateContact( const contact = await addOrUpdateContact(
contactBook.id, contactBook.id,
c.req.valid("json") c.req.valid("json")
); );
return c.json({ contactId: contact.id }); return c.json({ contactId: contact.id });
}); });
} }
export default upsertContact; export default upsertContact;