diff --git a/.replit b/.replit index ba2f351..6cd1be4 100644 --- a/.replit +++ b/.replit @@ -23,6 +23,10 @@ externalPort = 3000 localPort = 38451 externalPort = 3002 +[[ports]] +localPort = 40433 +externalPort = 3003 + [[ports]] localPort = 41343 externalPort = 3001 diff --git a/attached_assets/image_1758302026930.png b/attached_assets/image_1758302026930.png new file mode 100644 index 0000000..d5e49df Binary files /dev/null and b/attached_assets/image_1758302026930.png differ diff --git a/server/routes.ts b/server/routes.ts index a191d5f..d9e2c93 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -1419,8 +1419,7 @@ export async function registerRoutes(app: Express): Promise { } const commentId = parseInt(req.params.id); - const comments = await storage.getReconciliationComments(0); // Get all to find the comment - const comment = comments.find(c => c.id === commentId); + const comment = await storage.getReconciliationCommentById(commentId); if (!comment) { return res.status(404).json({ message: "Comment not found" }); @@ -1458,8 +1457,7 @@ export async function registerRoutes(app: Express): Promise { } const commentId = parseInt(req.params.id); - const comments = await storage.getReconciliationComments(0); // Get all to find the comment - const comment = comments.find(c => c.id === commentId); + const comment = await storage.getReconciliationCommentById(commentId); if (!comment) { return res.status(404).json({ message: "Comment not found" }); diff --git a/server/storage.ts b/server/storage.ts index 6cace28..5be6d7e 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -259,6 +259,7 @@ export interface IStorage { // Reconciliation Comments operations getReconciliationComments(deliveryId: number): Promise; + getReconciliationCommentById(id: number): Promise; createReconciliationComment(comment: InsertReconciliationComment): Promise; updateReconciliationComment(id: number, comment: Partial): Promise; deleteReconciliationComment(id: number): Promise; @@ -2650,6 +2651,7 @@ export class DatabaseStorage implements IStorage { deliveryId: reconciliationComments.deliveryId, groupId: reconciliationComments.groupId, content: reconciliationComments.content, + type: reconciliationComments.type, authorId: reconciliationComments.authorId, createdAt: reconciliationComments.createdAt, updatedAt: reconciliationComments.updatedAt, @@ -2695,6 +2697,60 @@ export class DatabaseStorage implements IStorage { })) as ReconciliationCommentWithRelations[]; } + async getReconciliationCommentById(id: number): Promise { + const [comment] = await db + .select({ + id: reconciliationComments.id, + deliveryId: reconciliationComments.deliveryId, + groupId: reconciliationComments.groupId, + content: reconciliationComments.content, + type: reconciliationComments.type, + authorId: reconciliationComments.authorId, + createdAt: reconciliationComments.createdAt, + updatedAt: reconciliationComments.updatedAt, + author: users, + group: groups, + delivery: { + id: deliveries.id, + orderId: deliveries.orderId, + supplierId: deliveries.supplierId, + groupId: deliveries.groupId, + scheduledDate: deliveries.scheduledDate, + deliveredDate: deliveries.deliveredDate, + quantity: deliveries.quantity, + unit: deliveries.unit, + status: deliveries.status, + notes: deliveries.notes, + blNumber: deliveries.blNumber, + blAmount: deliveries.blAmount, + invoiceReference: deliveries.invoiceReference, + invoiceAmount: deliveries.invoiceAmount, + reconciled: deliveries.reconciled, + validatedAt: deliveries.validatedAt, + createdBy: deliveries.createdBy, + createdAt: deliveries.createdAt, + updatedAt: deliveries.updatedAt, + } + }) + .from(reconciliationComments) + .leftJoin(users, eq(reconciliationComments.authorId, users.id)) + .leftJoin(groups, eq(reconciliationComments.groupId, groups.id)) + .leftJoin(deliveries, eq(reconciliationComments.deliveryId, deliveries.id)) + .where(eq(reconciliationComments.id, id)); + + if (!comment) return undefined; + + return { + ...comment, + delivery: { + ...comment.delivery, + supplier: {} as any, // Will be filled by relations if needed + group: comment.group!, + creator: {} as any, // Will be filled by relations if needed + } + } as ReconciliationCommentWithRelations; + } + async createReconciliationComment(commentData: InsertReconciliationComment): Promise { const [comment] = await db .insert(reconciliationComments) @@ -4621,6 +4677,38 @@ export class MemStorage implements IStorage { }); } + async getReconciliationCommentById(id: number): Promise { + const comment = this.reconciliationComments.get(id); + if (!comment) return undefined; + + const delivery = this.deliveries.get(comment.deliveryId); + const author = this.users.get(comment.authorId); + const group = this.groups.get(comment.groupId); + + if (!delivery || !author || !group) { + throw new Error('Missing related data for reconciliation comment'); + } + + const supplier = this.suppliers.get(delivery.supplierId); + const creator = this.users.get(delivery.createdBy); + + if (!supplier || !creator) { + throw new Error('Missing delivery related data for reconciliation comment'); + } + + return { + ...comment, + delivery: { + ...delivery, + supplier, + group, + creator, + }, + group, + author, + } as ReconciliationCommentWithRelations; + } + async createReconciliationComment(commentData: InsertReconciliationComment): Promise { const id = this.idCounters.reconciliationComment++; const comment: ReconciliationComment = {