summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-14 13:31:45 +0300
committereug-vs <eug-vs@keemail.me>2021-03-14 13:31:45 +0300
commit3a2cdd13b0374aab279b8dd819b03f82013cb026 (patch)
treeede046b9c7a0612379b6ac8395ca41f47f7bad5b
parentac9698ea0de17ab2d1fbfafead0f33295a402e28 (diff)
downloadcommercel-api-3a2cdd13b0374aab279b8dd819b03f82013cb026.tar.gz
feat: add Waybills service
-rw-r--r--src/models/waybill/waybill.model.ts4
-rw-r--r--src/models/waybill/waybill.schema.ts33
-rw-r--r--src/services/index.ts2
-rw-r--r--src/services/waybills.service.ts10
4 files changed, 49 insertions, 0 deletions
diff --git a/src/models/waybill/waybill.model.ts b/src/models/waybill/waybill.model.ts
new file mode 100644
index 0000000..3769eec
--- /dev/null
+++ b/src/models/waybill/waybill.model.ts
@@ -0,0 +1,4 @@
+import { Model, model } from 'mongoose';
+import { WaybillSchema, waybillSchema } from './waybill.schema';
+
+export default model<WaybillSchema, Model<WaybillSchema>>('Waybill', waybillSchema);
diff --git a/src/models/waybill/waybill.schema.ts b/src/models/waybill/waybill.schema.ts
new file mode 100644
index 0000000..ce14525
--- /dev/null
+++ b/src/models/waybill/waybill.schema.ts
@@ -0,0 +1,33 @@
+import { Document, Schema, Types } from 'mongoose';
+
+export interface WaybillSchema extends Document {
+ operation: 'in' | 'out';
+ productId: string;
+ quantity: number;
+ contractorId: string;
+ status: 'waiting' | 'executed' | 'cancelled';
+}
+
+export const waybillSchema = new Schema({
+ operation: {
+ type: String,
+ required: true,
+ },
+ contractorId: {
+ type: Types.ObjectId,
+ required: true,
+ },
+ productId: {
+ type: Types.ObjectId,
+ required: true,
+ },
+ quantity: {
+ type: Number,
+ min: 1,
+ },
+ status: {
+ type: String,
+ default: 'waiting',
+ },
+}, { timestamps: true });
+
diff --git a/src/services/index.ts b/src/services/index.ts
index 9b3511b..cabfff3 100644
--- a/src/services/index.ts
+++ b/src/services/index.ts
@@ -1,10 +1,12 @@
import { Application } from '@feathersjs/express';
import Products from './products.service';
import Contractors from './contractors.service';
+import Waybills from './waybills.service';
export default (app: Application): void => {
app.configure(Products);
app.configure(Contractors);
+ app.configure(Waybills);
app.get('/ping', (req, res) => res.send('pong'));
};
diff --git a/src/services/waybills.service.ts b/src/services/waybills.service.ts
new file mode 100644
index 0000000..7aea1e3
--- /dev/null
+++ b/src/services/waybills.service.ts
@@ -0,0 +1,10 @@
+import { Application } from '@feathersjs/express';
+import service from 'feathers-mongoose';
+import Model from '../models/waybill/waybill.model';
+
+const waybills = service({ Model });
+
+export default (app: Application): void => {
+ app.use('/waybills', waybills);
+};
+