ADDED: new add notes feature for orders backend and frontend
This commit is contained in:
@@ -2,6 +2,7 @@ import type { Address, AuthUser } from "@orderops/shared";
|
||||
import type { FastifyPluginAsync, FastifyRequest } from "fastify";
|
||||
import { requireEmployeeUser } from "../auth/current-user";
|
||||
import type { DatabaseContext } from "../db/database";
|
||||
import { addOrderNote } from "./add-order-note";
|
||||
import { cancelOrder } from "./cancel-order";
|
||||
import { getOrder } from "./get-order";
|
||||
import { listAuditEvents } from "./list-audit-events";
|
||||
@@ -33,6 +34,10 @@ interface CancelBody {
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
interface NoteBody {
|
||||
body: string;
|
||||
}
|
||||
|
||||
type AuthenticatedRequest = FastifyRequest & { currentUser: AuthUser };
|
||||
|
||||
export const registerOrderRoutes: FastifyPluginAsync<OrderRouteOptions> = async (app, options) => {
|
||||
@@ -69,6 +74,31 @@ export const registerOrderRoutes: FastifyPluginAsync<OrderRouteOptions> = async
|
||||
|
||||
app.get<{ Params: IdParams }>("/orders/:orderId/audit-events", async (request) => listAuditEvents(options.db, request.params.orderId));
|
||||
|
||||
app.post<{ Params: IdParams; Body: NoteBody }>("/orders/:orderId/notes", {
|
||||
schema: {
|
||||
body: {
|
||||
type: "object",
|
||||
required: ["body"],
|
||||
properties: {
|
||||
body: { type: "string", minLength: 1, maxLength: 1999 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}, async (request, reply) => {
|
||||
const currentUser = (request as AuthenticatedRequest).currentUser;
|
||||
const result = await addOrderNote(options.db, {
|
||||
orderId: request.params.orderId,
|
||||
authorUserId: currentUser.id,
|
||||
body: request.body.body
|
||||
});
|
||||
|
||||
if (result.statusCode !== 200) {
|
||||
return reply.code(result.statusCode).send({ message: result.message });
|
||||
}
|
||||
|
||||
return result.note;
|
||||
});
|
||||
|
||||
app.post<{ Params: OrderItemParams; Body: QuantityBody }>("/orders/:orderId/items/:itemId/quantity", {
|
||||
schema: {
|
||||
body: {
|
||||
|
||||
Reference in New Issue
Block a user