From 053cdf0a6fe8ffde9242f7f23af542b1db85fc56 Mon Sep 17 00:00:00 2001 From: "Md. Mosiur Rahman" Date: Mon, 24 Mar 2025 00:09:15 +0600 Subject: [PATCH] Added the backend code for completed task and also frontend is completed --- backend-server/src/index.ts | 18 +++++- .../client-service.component.html | 59 ++++++++++--------- .../client-service.component.ts | 23 +++++--- .../client-service/client-service.model.ts | 1 + .../client-service/client-service.service.ts | 6 ++ .../pages/dashboard/dashboard-data.ts | 7 +++ 6 files changed, 75 insertions(+), 39 deletions(-) diff --git a/backend-server/src/index.ts b/backend-server/src/index.ts index 0532900..4bf16a8 100644 --- a/backend-server/src/index.ts +++ b/backend-server/src/index.ts @@ -270,8 +270,22 @@ app.post("/api/delivery/create", async(req,res)=>{ await newDelivery.save().then(()=>res.status(201).json({ message: "Delivery saved successfully", success: true })).catch((err)=>res.status(500).json({ error: err.message })); }) -//TODO: Check create and read from frontend -//TODO: Add another Field to DeliverySchema called "isCompleted: boolean" - remove the table from DB FIRST +app.put("/api/delivery/update/:id", async(req, res)=> { + const filter = { _id : req.params.id } + const update = { delivery_status : req.body.delivery_status } + console.log(update) + if (!req.body.delivery_status) { + res.status(404).send("Delivery status is required") + } + + const updateClient = await DeliveryModel.findOneAndUpdate(filter,update) + + if (!updateClient) { + res.send(404).send("Client not Found") + } + res.status(200).send("Delivery Type Updated") +}) + //TODO: FIx the file structure //TODO: delivery Update //TODO: delivery Delete diff --git a/src/app/components/pages/client-service/client-service.component.html b/src/app/components/pages/client-service/client-service.component.html index b8f45b6..cd91ae2 100644 --- a/src/app/components/pages/client-service/client-service.component.html +++ b/src/app/components/pages/client-service/client-service.component.html @@ -1,31 +1,4 @@
-
-

Todays Task

- - - - - - - - - - - - - - - - - - - - - -
Client NameDelivery StatusDelivery TypeDelivery DateAction
{{client.client_name}}{{client.delivery_status}}{{client.delivery_type}}{{client.delivery_date }} - -
-
@@ -53,6 +26,34 @@
+
+

Todays Task

+ + + + + + + + + + + + + + + + + + + + + +
Client NameDelivery StatusDelivery TypeDelivery DateAction
{{client.client_name}}{{client.delivery_status}}{{client.delivery_type}}{{client.delivery_date }} + +
+
+

Pending Task

@@ -68,13 +69,13 @@ - + {{client.client_name}} {{client.delivery_status}} {{client.delivery_type}} {{client.delivery_date }} - + diff --git a/src/app/components/pages/client-service/client-service.component.ts b/src/app/components/pages/client-service/client-service.component.ts index 2bed81f..0e3e0d1 100644 --- a/src/app/components/pages/client-service/client-service.component.ts +++ b/src/app/components/pages/client-service/client-service.component.ts @@ -52,17 +52,24 @@ export class ClientServiceComponent implements OnInit, OnDestroy { this.allDeliverySubscription.unsubscribe(); } - completedTask() { - - } - - addNewClient() { - this.clientDeliveryService.addNewClientToDB(this.newClient).subscribe(res=>{ - console.log(res); - this.newClient = new DeliveryModel(); + completedTask(client: DeliveryModel): void { + client.delivery_status = "Completed"; + //TODO11: When Completed is pressed send request to backend to change delivery Status to completed + this.clientDeliveryService.updateStatus(client).subscribe(response=>{ + console.log(response) this.clientDeliveryService.allDelivery().subscribe(data=>{ this.allDeliveryTasks = data; }) }) } + + addNewClient() { + this.clientDeliveryService.addNewClientToDB(this.newClient).subscribe(response=>{ + console.log("response", response); + this.newClient = new DeliveryModel(); + this.clientDeliveryService.allDelivery().subscribe(data=>{ + this.allDeliveryTasks = data; + },error=>{console.log("error", error)}) + }) + } } diff --git a/src/app/components/pages/client-service/client-service.model.ts b/src/app/components/pages/client-service/client-service.model.ts index 408a59a..12ad3fa 100644 --- a/src/app/components/pages/client-service/client-service.model.ts +++ b/src/app/components/pages/client-service/client-service.model.ts @@ -1,4 +1,5 @@ export class DeliveryModel { + _id?: string; client_name!: string; // Termination, provision, Test delivery_type!: string; diff --git a/src/app/components/pages/client-service/client-service.service.ts b/src/app/components/pages/client-service/client-service.service.ts index 113b102..6a7e460 100644 --- a/src/app/components/pages/client-service/client-service.service.ts +++ b/src/app/components/pages/client-service/client-service.service.ts @@ -20,4 +20,10 @@ export class ClientDeliveryService { addNewClientToDB(newClient: DeliveryModel){ return this.httpClient.post("http://localhost:3000/api/delivery/create", newClient) } + + updateStatus(newStatus: DeliveryModel) { + return this.httpClient.put(`http://localhost:3000/api/delivery/update/${newStatus._id}`, newStatus, {responseType: 'text'}) + } + + } \ No newline at end of file diff --git a/src/app/components/pages/dashboard/dashboard-data.ts b/src/app/components/pages/dashboard/dashboard-data.ts index 730c315..6d4a1e0 100644 --- a/src/app/components/pages/dashboard/dashboard-data.ts +++ b/src/app/components/pages/dashboard/dashboard-data.ts @@ -132,3 +132,10 @@ export const service_links: navLink[] =[ "url" : "https://s3.brilliant.com.bd/bucket-1-ee86738d/client-doc/friendship-diagram.html" } ] + + export const documents = [ + { + "name": "Test", + "url" : "Test" + } + ]