summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-04-24 20:34:00 +0300
committereug-vs <eug-vs@keemail.me>2021-04-24 20:34:00 +0300
commit593159c22c2acad599b67d1b128a52232b79a34b (patch)
tree02363af7bf3b8919260b70ca6e6415169c0879d2
parent874b97bc01b691d7a4553c0ffb337bfaa003d1ff (diff)
downloadcommercel-api-593159c22c2acad599b67d1b128a52232b79a34b.tar.gz
feat: add accounts service
-rw-r--r--src/models/account/account.model.ts4
-rw-r--r--src/models/account/account.schema.ts23
-rw-r--r--src/services/accounts.service.ts10
-rw-r--r--src/services/index.ts2
4 files changed, 39 insertions, 0 deletions
diff --git a/src/models/account/account.model.ts b/src/models/account/account.model.ts
new file mode 100644
index 0000000..1df1406
--- /dev/null
+++ b/src/models/account/account.model.ts
@@ -0,0 +1,4 @@
+import { Model, model } from 'mongoose';
+import { AccountSchema, accountSchema } from './account.schema';
+
+export default model<AccountSchema, Model<AccountSchema>>('Account', accountSchema);
diff --git a/src/models/account/account.schema.ts b/src/models/account/account.schema.ts
new file mode 100644
index 0000000..3ce3983
--- /dev/null
+++ b/src/models/account/account.schema.ts
@@ -0,0 +1,23 @@
+import { Document, Schema } from 'mongoose';
+
+export interface AccountSchema extends Document {
+ name: string;
+ code: string;
+ balance: number;
+}
+
+export const accountSchema = new Schema({
+ name: {
+ type: String,
+ required: true,
+ },
+ code: {
+ type: String,
+ required: true,
+ },
+ balance: {
+ type: Number,
+ default: 0,
+ },
+}, { timestamps: true });
+
diff --git a/src/services/accounts.service.ts b/src/services/accounts.service.ts
new file mode 100644
index 0000000..cf22a9b
--- /dev/null
+++ b/src/services/accounts.service.ts
@@ -0,0 +1,10 @@
+import { Application } from '@feathersjs/express';
+import service from 'feathers-mongoose';
+import Model from '../models/account/account.model';
+
+const Accounts = service({ Model, whitelist: ['$options', '$regex'] });
+
+export default (app: Application): void => {
+ app.use('/accounts', Accounts);
+};
+
diff --git a/src/services/index.ts b/src/services/index.ts
index b94380d..499ab68 100644
--- a/src/services/index.ts
+++ b/src/services/index.ts
@@ -1,4 +1,5 @@
import { Application } from '@feathersjs/express';
+import Accounts from './accounts.service';
import Products from './products.service';
import Contractors from './contractors.service';
import Waybills from './waybills.service';
@@ -9,6 +10,7 @@ import sortByDate from '../hooks/sortByDate';
import ignoreCaseRegex from '../hooks/ignoreCaseRegex';
export default (app: Application): void => {
+ app.configure(Accounts);
app.configure(Products);
app.configure(Contractors);
app.configure(Waybills);