Added the backend code for completed task and also frontend is completed

This commit is contained in:
Md. Mosiur Rahman
2025-03-24 00:09:15 +06:00
parent 55f7f9eaa2
commit 053cdf0a6f
6 changed files with 75 additions and 39 deletions

View File

@@ -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 })); 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 app.put("/api/delivery/update/:id", async(req, res)=> {
//TODO: Add another Field to DeliverySchema called "isCompleted: boolean" - remove the table from DB FIRST 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: FIx the file structure
//TODO: delivery Update //TODO: delivery Update
//TODO: delivery Delete //TODO: delivery Delete

View File

@@ -1,31 +1,4 @@
<div class="container"> <div class="container">
<div class="client_list">
<h1>Todays Task</h1>
<table>
<thead>
<tr>
<th>Client Name</th>
<th>Delivery Status</th>
<th>Delivery Type</th>
<th>Delivery Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let client of allDeliveryTasks">
<ng-container *ngIf="client.delivery_date === today && client.delivery_status !='Completed'">
<td>{{client.client_name}}</td>
<td>{{client.delivery_status}}</td>
<td>{{client.delivery_type}}</td>
<td>{{client.delivery_date }}</td>
<td>
<button (click)="completedTask()">Completed</button>
</td>
</ng-container>
</tr>
</tbody>
</table>
</div>
<div class="form-container"> <div class="form-container">
<form action="" #clientForm="ngForm" (ngSubmit)="addNewClient()"> <form action="" #clientForm="ngForm" (ngSubmit)="addNewClient()">
<label for="clientName">Client Name</label> <label for="clientName">Client Name</label>
@@ -53,6 +26,34 @@
<button type="submit" [disabled]="clientForm.invalid">Add</button> <button type="submit" [disabled]="clientForm.invalid">Add</button>
</form> </form>
</div> </div>
<div class="client_list today-task">
<h1>Todays Task</h1>
<table>
<thead>
<tr>
<th>Client Name</th>
<th>Delivery Status</th>
<th>Delivery Type</th>
<th>Delivery Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let client of allDeliveryTasks">
<ng-container *ngIf="client.delivery_date === today && client.delivery_status !='Completed'">
<td>{{client.client_name}}</td>
<td>{{client.delivery_status}}</td>
<td>{{client.delivery_type}}</td>
<td>{{client.delivery_date }}</td>
<td>
<button (click)="completedTask(client)">Completed</button>
</td>
</ng-container>
</tr>
</tbody>
</table>
</div>
<div class="pending-cotainer"> <div class="pending-cotainer">
<div class="client_list"> <div class="client_list">
<h1>Pending Task</h1> <h1>Pending Task</h1>
@@ -68,13 +69,13 @@
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let client of allDeliveryTasks"> <tr *ngFor="let client of allDeliveryTasks">
<ng-container *ngIf="client.delivery_date < today"> <ng-container *ngIf="client.delivery_date < today && client.delivery_status !='Completed'">
<td>{{client.client_name}}</td> <td>{{client.client_name}}</td>
<td>{{client.delivery_status}}</td> <td>{{client.delivery_status}}</td>
<td>{{client.delivery_type}}</td> <td>{{client.delivery_type}}</td>
<td>{{client.delivery_date }}</td> <td>{{client.delivery_date }}</td>
<td> <td>
<button (click)="completedTask()">Completed</button> <button (click)="completedTask(client)">Completed</button>
</td> </td>
</ng-container> </ng-container>
</tr> </tr>

View File

@@ -52,17 +52,24 @@ export class ClientServiceComponent implements OnInit, OnDestroy {
this.allDeliverySubscription.unsubscribe(); this.allDeliverySubscription.unsubscribe();
} }
completedTask() { 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=>{
addNewClient() { console.log(response)
this.clientDeliveryService.addNewClientToDB(this.newClient).subscribe(res=>{
console.log(res);
this.newClient = new DeliveryModel();
this.clientDeliveryService.allDelivery().subscribe(data=>{ this.clientDeliveryService.allDelivery().subscribe(data=>{
this.allDeliveryTasks = 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)})
})
}
} }

View File

@@ -1,4 +1,5 @@
export class DeliveryModel { export class DeliveryModel {
_id?: string;
client_name!: string; client_name!: string;
// Termination, provision, Test // Termination, provision, Test
delivery_type!: string; delivery_type!: string;

View File

@@ -20,4 +20,10 @@ export class ClientDeliveryService {
addNewClientToDB(newClient: DeliveryModel){ addNewClientToDB(newClient: DeliveryModel){
return this.httpClient.post("http://localhost:3000/api/delivery/create", newClient) 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'})
}
} }

View File

@@ -132,3 +132,10 @@ export const service_links: navLink[] =[
"url" : "https://s3.brilliant.com.bd/bucket-1-ee86738d/client-doc/friendship-diagram.html" "url" : "https://s3.brilliant.com.bd/bucket-1-ee86738d/client-doc/friendship-diagram.html"
} }
] ]
export const documents = [
{
"name": "Test",
"url" : "Test"
}
]