diff options
author | eug-vs <eug-vs@keemail.me> | 2021-03-14 06:44:05 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2021-03-14 06:44:05 +0300 |
commit | 1b86dcef9fd537db800e0df2c2f3889ffbc69723 (patch) | |
tree | f44f2d6a21075ac69d01b8b4a298939146fd9bd3 | |
parent | dc00c06719b5192518a67177caafe28f5027c16c (diff) | |
download | commercel-api-1b86dcef9fd537db800e0df2c2f3889ffbc69723.tar.gz |
feat: add products service
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/app.ts (renamed from app.ts) | 4 | ||||
-rw-r--r-- | src/models/product/product.model.ts | 4 | ||||
-rw-r--r-- | src/models/product/product.schema.ts | 18 | ||||
-rw-r--r-- | src/services/index.ts | 8 | ||||
-rw-r--r-- | src/services/products/products.service.ts | 10 | ||||
-rw-r--r-- | yarn.lock | 22 |
7 files changed, 63 insertions, 4 deletions
diff --git a/package.json b/package.json index 001dc3c..f60c749 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@feathersjs/socketio": "^4.5.11", "bluebird": "^3.7.2", "cors": "^2.8.5", + "feathers-mongoose": "^8.3.1", "mongoose": "^5.12.0" }, "devDependencies": { @@ -4,7 +4,7 @@ import socketio from '@feathersjs/socketio'; import '@feathersjs/transport-commons'; import cors from 'cors'; -//import services from './services'; +import services from './services'; const app = express(feathers()); @@ -17,7 +17,7 @@ app.use(cors()); app.configure(express.rest()); app.configure(socketio()); -//app.configure(services); +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); +}; + @@ -2,12 +2,21 @@ # yarn lockfile v1 -"@feathersjs/commons@^4.5.11": +"@feathersjs/adapter-commons@^4.4.3": + version "4.5.11" + resolved "https://registry.yarnpkg.com/@feathersjs/adapter-commons/-/adapter-commons-4.5.11.tgz#b7eaa9a9124591aa639f9080a7522fa60fb29915" + integrity sha512-qJ+P/6GLR3KfXhzgRkvl3p66YmaTxLO1js1Jzs+d5QnnUYx+jWSV7tzYVZoVjQSlF8ht/zh9N5qfh0RV9w1E+w== + dependencies: + "@feathersjs/commons" "^4.5.11" + "@feathersjs/errors" "^4.5.11" + "@feathersjs/feathers" "^4.5.11" + +"@feathersjs/commons@^4.4.3", "@feathersjs/commons@^4.5.11": version "4.5.11" resolved "https://registry.yarnpkg.com/@feathersjs/commons/-/commons-4.5.11.tgz#4c9d04e6996b823981b714312f7915c4469f0ffd" integrity sha512-it/9lc0OER36+2zidopWo6Z4xRqNImQ+qegyQdHEuIDpEsYLXAv6MVHuDccaW2x2UmW5pce75UB7DhQ8yh8J/Q== -"@feathersjs/errors@^4.5.11": +"@feathersjs/errors@^4.4.3", "@feathersjs/errors@^4.5.11": version "4.5.11" resolved "https://registry.yarnpkg.com/@feathersjs/errors/-/errors-4.5.11.tgz#419b4dd9b557fe7a87978363175cbd5e06f8b3b9" integrity sha512-KzkUqmaV7/SGK6SM/ILXjMI/EHOGKQE4GgDHCsB4+mcIwb8IZboeHL6IkYjh6MvwjKNDyS728McZvcflDGn/fA== @@ -468,6 +477,15 @@ express@^4.17.1: utils-merge "1.0.1" vary "~1.1.2" +feathers-mongoose@^8.3.1: + version "8.3.1" + resolved "https://registry.yarnpkg.com/feathers-mongoose/-/feathers-mongoose-8.3.1.tgz#240ecb746e1da26e05fb85d16148c84ec41f8a80" + integrity sha512-N89kOOp06PaYwyK2REI56fDSPDBKYuJc/E6uqCUu4+nQ6wvM3m+L4aX6lfXWBowD7MWpFzNDG/T9GOGjzrQ55g== + dependencies: + "@feathersjs/adapter-commons" "^4.4.3" + "@feathersjs/commons" "^4.4.3" + "@feathersjs/errors" "^4.4.3" + finalhandler@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.1.2.tgz#b7e7d000ffd11938d0fdb053506f6ebabe9f587d" |