summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-18 22:10:29 +0300
committereug-vs <eug-vs@keemail.me>2021-03-18 22:10:29 +0300
commit3109e25f2cabb85bbccf4ba509e112e49f5c0120 (patch)
tree32dc6d10575debbd970a9936e196638f3a1354f1
parent93e5f7eda2f9bf0d274d793f7e823e35502f4763 (diff)
downloadcommercel-api-3109e25f2cabb85bbccf4ba509e112e49f5c0120.tar.gz
feat: add date to Waybill
-rw-r--r--package.json2
-rw-r--r--src/models/waybill/waybill.schema.ts5
-rw-r--r--src/services/waybills.service.ts6
-rw-r--r--yarn.lock12
4 files changed, 23 insertions, 2 deletions
diff --git a/package.json b/package.json
index d9579fe..a6f7b90 100644
--- a/package.json
+++ b/package.json
@@ -16,11 +16,13 @@
"@types/cors": "^2.8.10",
"@types/exceljs": "^1.3.0",
"@types/lodash": "^4.14.168",
+ "@types/moment": "^2.13.0",
"@types/mongoose": "^5.10.3",
"bluebird": "^3.7.2",
"cors": "^2.8.5",
"feathers-hooks-common": "^5.0.5",
"feathers-mongoose": "^8.3.1",
+ "moment": "^2.29.1",
"mongoose": "^5.12.0",
"ts-node": "^9.1.1",
"typescript": "^4.2.3"
diff --git a/src/models/waybill/waybill.schema.ts b/src/models/waybill/waybill.schema.ts
index bbebcd4..55d2127 100644
--- a/src/models/waybill/waybill.schema.ts
+++ b/src/models/waybill/waybill.schema.ts
@@ -1,6 +1,7 @@
import { Document, Schema, Types } from 'mongoose';
export interface WaybillSchema extends Document {
+ date: string;
operation: 'in' | 'out';
records: [{
productId: string;
@@ -28,6 +29,10 @@ const recordSchema = new Schema({
});
export const waybillSchema = new Schema({
+ date: {
+ type: Date,
+ required: true,
+ },
operation: {
type: String,
required: true,
diff --git a/src/services/waybills.service.ts b/src/services/waybills.service.ts
index ce820bc..e36e4f9 100644
--- a/src/services/waybills.service.ts
+++ b/src/services/waybills.service.ts
@@ -4,6 +4,7 @@ import service from 'feathers-mongoose';
import { populate, alterItems } from 'feathers-hooks-common';
import Bluebird from 'bluebird';
import _ from 'lodash';
+import moment from 'moment';
import Model from '../models/waybill/waybill.model';
import { WaybillSchema } from '../models/waybill/waybill.schema';
@@ -54,11 +55,12 @@ const reflectStatus = async (context: HookContext): Promise<HookContext> => {
const addFields = (item: WaybillSchema) => {
- const { operation, records } = item;
+ const { operation, records, date } = item;
const total = item.records.reduce((sum, record) => sum + record.price * record.quantity, 0);
const op = operation === 'in' ? 'приход' : 'расход';
const name = `Накладная: ${op} $${total}`;
- return { name, total, ...item };
+ const formattedDate = moment(date).format('YYYY-MM-DD');
+ return { ...item, name, total, date: formattedDate };
};
export default (app: Application): void => {
diff --git a/yarn.lock b/yarn.lock
index 7bddf0d..63cb409 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -173,6 +173,13 @@
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==
+"@types/moment@^2.13.0":
+ version "2.13.0"
+ resolved "https://registry.yarnpkg.com/@types/moment/-/moment-2.13.0.tgz#604ebd189bc3bc34a1548689404e61a2a4aac896"
+ integrity sha1-YE69GJvDvDShVIaJQE5hoqSqyJY=
+ dependencies:
+ moment "*"
+
"@types/mongodb@*", "@types/mongodb@^3.5.27":
version "3.6.9"
resolved "https://registry.yarnpkg.com/@types/mongodb/-/mongodb-3.6.9.tgz#55f7e5b04f33904a12d6f0ab4f5d119a5062ade4"
@@ -1100,6 +1107,11 @@ minimist@^1.2.5:
dependencies:
minimist "^1.2.5"
+moment@*, moment@^2.29.1:
+ version "2.29.1"
+ resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
+ integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
+
mongodb@3.6.4:
version "3.6.4"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-3.6.4.tgz#ca59fd65b06831308262372ef9df6b78f9da97be"