From 1b86dcef9fd537db800e0df2c2f3889ffbc69723 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 14 Mar 2021 06:44:05 +0300 Subject: feat: add products service --- src/app.ts | 24 ++++++++++++++++++++++++ src/models/product/product.model.ts | 4 ++++ src/models/product/product.schema.ts | 18 ++++++++++++++++++ src/services/index.ts | 8 ++++++++ src/services/products/products.service.ts | 10 ++++++++++ 5 files changed, 64 insertions(+) create mode 100644 src/app.ts create mode 100644 src/models/product/product.model.ts create mode 100644 src/models/product/product.schema.ts create mode 100644 src/services/index.ts create mode 100644 src/services/products/products.service.ts (limited to 'src') 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>('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); +}; + -- cgit v1.2.3