35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { createRoute } from "../../../../../modules/api-utils/createRoute";
|
|
import { opportunities } from "../../../../../managers/opportunities";
|
|
import { apiResponse } from "../../../../../modules/api-utils/apiResponse";
|
|
import { ContentfulStatusCode } from "hono/utils/http-status";
|
|
import { authMiddleware } from "../../../../middleware/authorization";
|
|
import GenericError from "../../../../../Errors/GenericError";
|
|
|
|
/* GET /v1/sales/opportunities/:identifier/notes/:noteId */
|
|
export default createRoute(
|
|
"get",
|
|
["/opportunities/:identifier/notes/:noteId"],
|
|
async (c) => {
|
|
const identifier = c.req.param("identifier");
|
|
const noteId = Number(c.req.param("noteId"));
|
|
|
|
if (isNaN(noteId))
|
|
throw new GenericError({
|
|
status: 400,
|
|
name: "InvalidNoteId",
|
|
message: "Note ID must be a number",
|
|
});
|
|
|
|
const item = await opportunities.fetchRecord(identifier);
|
|
const data = await item.fetchNote(noteId);
|
|
|
|
const response = apiResponse.successful(
|
|
"Opportunity note fetched successfully!",
|
|
data,
|
|
);
|
|
|
|
return c.json(response, response.status as ContentfulStatusCode);
|
|
},
|
|
authMiddleware({ permissions: ["sales.opportunity.fetch"] }),
|
|
);
|