summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-14 06:44:05 +0300
committereug-vs <eug-vs@keemail.me>2021-03-14 06:44:05 +0300
commit1b86dcef9fd537db800e0df2c2f3889ffbc69723 (patch)
treef44f2d6a21075ac69d01b8b4a298939146fd9bd3 /src
parentdc00c06719b5192518a67177caafe28f5027c16c (diff)
downloadcommercel-api-1b86dcef9fd537db800e0df2c2f3889ffbc69723.tar.gz
feat: add products service
Diffstat (limited to 'src')
-rw-r--r--src/app.ts24
-rw-r--r--src/models/product/product.model.ts4
-rw-r--r--src/models/product/product.schema.ts18
-rw-r--r--src/services/index.ts8
-rw-r--r--src/services/products/products.service.ts10
5 files changed, 64 insertions, 0 deletions
diff --git a/src/app.ts b/src/app.ts
new file mode 100644
index 0000000..4b5ac3b
--- /dev/null
+++ b/src/app.ts
@@ -0,0 +1,24 @@
+import feathers from '@feathersjs/feathers';
+import express from '@feathersjs/express';
+import socketio from '@feathersjs/socketio';
+import '@feathersjs/transport-commons';
+import cors from 'cors';
+
+import services from './services';
+
+
+const app = express(feathers());
+
+app.use(express.json());
+app.use(express.urlencoded({ extended: true }));
+app.use(express.static(__dirname));
+app.use(express.errorHandler());
+app.use(cors());
+
+app.configure(express.rest());
+app.configure(socketio());
+app.configure(services);
+
+
+export default app;
+
diff --git a/src/models/product/product.model.ts b/src/models/product/product.model.ts
new file mode 100644
index 0000000..557b5be
--- /dev/null
+++ b/src/models/product/product.model.ts
@@ -0,0 +1,4 @@
+import { Model, model } from 'mongoose';
+import { ProductSchema, productSchema } from './product.schema';
+
+export default model<ProductSchema, Model<ProductSchema>>('Product', productSchema);
diff --git a/src/models/product/product.schema.ts b/src/models/product/product.schema.ts
new file mode 100644
index 0000000..8f488f3
--- /dev/null
+++ b/src/models/product/product.schema.ts
@@ -0,0 +1,18 @@
+import { Document, Schema, Types } from 'mongoose';
+
+export interface ProductSchema extends Document {
+ name: string;
+ description: string;
+ price: number;
+ quantity: number;
+ specs: any;
+}
+
+export const productSchema = new Schema({
+ name: String,
+ description: String,
+ price: Number,
+ quantity: Number,
+ specs: Object
+}, { timestamps: true });
+
diff --git a/src/services/index.ts b/src/services/index.ts
new file mode 100644
index 0000000..d35ac27
--- /dev/null
+++ b/src/services/index.ts
@@ -0,0 +1,8 @@
+import { Application } from '@feathersjs/express';
+import Products from './products/products.service';
+
+export default (app: Application): void => {
+ app.configure(Products);
+
+ app.get('/ping', (req, res) => res.send('pong'));
+};
diff --git a/src/services/products/products.service.ts b/src/services/products/products.service.ts
new file mode 100644
index 0000000..6461dae
--- /dev/null
+++ b/src/services/products/products.service.ts
@@ -0,0 +1,10 @@
+import { Application } from '@feathersjs/express';
+import service from 'feathers-mongoose';
+import Model from '../../models/product/product.model';
+
+const Products = service({ Model });
+
+export default (app: Application): void => {
+ app.use('/products', Products);
+};
+