mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Add ability to retrieve specific comments for reconciliation process
Update routes to use a new method for fetching a single reconciliation comment by ID, replacing the previous approach of fetching all comments and filtering client-side. This change is reflected in both `routes.ts` and `storage.ts`, where a new `getReconciliationCommentById` method is introduced in the `IStorage` interface and implemented in `DatabaseStorage` and `MemStorage`. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1e4433b5-47ab-464c-b663-fea2e53367dd Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/1e4433b5-47ab-464c-b663-fea2e53367dd/waxFZ5i
This commit is contained in:
1 parent
5f1229c6e1
commit
2e59eec409
4 files changed
+94
-4
No files matched your search
+2
-4
@@ -1419,8 +1419,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
|
||||
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<Server> {
|
||||
}
|
||||
|
||||
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" });
|
||||
|
||||
@@ -259,6 +259,7 @@ export interface IStorage {
|
||||
|
||||
// Reconciliation Comments operations
|
||||
getReconciliationComments(deliveryId: number): Promise<ReconciliationCommentWithRelations[]>;
|
||||
getReconciliationCommentById(id: number): Promise<ReconciliationCommentWithRelations | undefined>;
|
||||
createReconciliationComment(comment: InsertReconciliationComment): Promise<ReconciliationComment>;
|
||||
updateReconciliationComment(id: number, comment: Partial<InsertReconciliationComment>): Promise<ReconciliationComment>;
|
||||
deleteReconciliationComment(id: number): Promise<void>;
|
||||
@@ -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<ReconciliationCommentWithRelations | undefined> {
|
||||
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<ReconciliationComment> {
|
||||
const [comment] = await db
|
||||
.insert(reconciliationComments)
|
||||
@@ -4621,6 +4677,38 @@ export class MemStorage implements IStorage {
|
||||
});
|
||||
}
|
||||
|
||||
async getReconciliationCommentById(id: number): Promise<ReconciliationCommentWithRelations | undefined> {
|
||||
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<ReconciliationComment> {
|
||||
const id = this.idCounters.reconciliationComment++;
|
||||
const comment: ReconciliationComment = {
|
||||
|
||||
Reference in new issue
Block a user