Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit d33b828

Browse files
committed
finished accept shipment route;
now switches item shipped; now creates new log of driver with accepted shipments;
1 parent 5ea15cf commit d33b828

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
lines changed

‎src/accept-shipments/accept-shipments.controller.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ export class AcceptShipmentsController {
1111
if (!this.validateShipments(body)){
1212
res.status(406).send({message: 'Invalid Parameters'});
1313
} else {
14+
await body.shipments.forEach(item => {
15+
this.db.setItemAsShipped(item).then(async () => {
16+
await this.db.createNewLog(body).then(() => {
17+
18+
}).catch((err) => {
19+
res.status(406).send(err);
20+
})
21+
}).catch((err) => {
22+
res.status(406).send(err);
23+
});
24+
});
25+
1426
res.status(200).send({message: 'Okay'});
1527
}
1628

‎src/accept-shipments/accept-shipments.module.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { AcceptShipmentsController } from './accept-shipments.controller';
33
import { MongooseModule } from '@nestjs/mongoose';
44
import { DatabaseService } from 'services/database.service';
55
import { ShipmentSchema } from 'schemas/shipment-schema/shipment-schema';
6+
import { ShipmentLogSchema } from './../schemas/shipment-log/shipment-log-schema';
67

78
@Module({
89
imports: [
910
HttpModule,
10-
MongooseModule.forFeature([{ name: 'Shipments', schema: ShipmentSchema }]),
11+
MongooseModule.forFeature([
12+
{ name: 'Shipments', schema: ShipmentSchema },
13+
{ name: 'ShipmentLog', schema: ShipmentLogSchema}]),
1114
],
1215
controllers: [AcceptShipmentsController],
1316
providers: [DatabaseService],

‎src/find-shipment/find-shipment.module.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { ShipmentSchema } from './../schemas/shipment-schema/shipment-schema';
33
import { MongooseModule } from '@nestjs/mongoose';
44
import { Module, HttpModule } from '@nestjs/common';
55
import { FindShipmentController } from './find-shipment.controller';
6+
import { ShipmentLogSchema } from 'schemas/shipment-log/shipment-log-schema';
67

78
@Module({
89
imports: [
910
HttpModule,
10-
MongooseModule.forFeature([{ name: 'Shipments', schema: ShipmentSchema }]),
11+
MongooseModule.forFeature([
12+
{ name: 'Shipments', schema: ShipmentSchema },
13+
{ name: 'ShipmentLog', schema: ShipmentLogSchema}]),
1114
],
1215
controllers: [FindShipmentController],
1316
providers: [DatabaseService],

‎src/interfaces/shipmentLog.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class ShipmentLog {
2+
public readonly driverid: string;
3+
public readonly shipments: [string];
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as mongoose from 'mongoose';
2+
3+
export const ShipmentLogSchema = new mongoose.Schema({
4+
driverid: String,
5+
shipments: [String],
6+
});

‎src/services/database.service.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,28 @@ import { Injectable } from '@nestjs/common';
33
import { InjectModel } from '@nestjs/mongoose';
44
import { Model } from 'mongoose';
55
import { Shipments } from 'interfaces/shipments';
6+
import { ShipmentLog } from 'interfaces/shipmentLog';
67

78
@Injectable()
89
export class DatabaseService {
910
constructor(
1011
@InjectModel('Shipments') private readonly shipmentsmodel: Model<Shipments>,
12+
@InjectModel('ShipmentLog') private readonly shipmentlogmodel: Model<ShipmentLog>,
1113
) {}
1214

1315
async findAllShipments(): Promise<any> {
1416
return await this.shipmentsmodel.find().exec();
1517
}
18+
19+
async setItemAsShipped(itemID): Promise<any>{
20+
return await this.shipmentsmodel.findOneAndUpdate({id: itemID}, {Shipped: true}, (err, doc) => {
21+
return err ? err : doc;
22+
});
23+
}
24+
25+
async createNewLog(logItem){
26+
const log = new this.shipmentlogmodel(logItem);
27+
return await log.save();
28+
}
29+
1630
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /