diff --git a/examples_new/microservices/items/src/controllers/itemController.ts b/examples_new/microservices/items/src/controllers/itemController.ts index 1954d8f60..3467fdaa9 100644 --- a/examples_new/microservices/items/src/controllers/itemController.ts +++ b/examples_new/microservices/items/src/controllers/itemController.ts @@ -1,22 +1,14 @@ import { Response } from 'express'; import axios, { AxiosError } from 'axios'; -import { - BadRequestError, - CurrentUserRequest, - EventTypes, - NotAuthorizedError, -} from '@chronosrx/common'; +import { BadRequestError, CurrentUserRequest, EventTypes } from '@chronosrx/common'; import { Item } from '../models/items'; -// current users can create items to sell export const createItem = async (req: CurrentUserRequest, res: Response) => { - // req.body consists of itemName and unitPrice const { itemName } = req.body; if (!itemName) { throw new BadRequestError('Invalid inputs'); } - // new item is created with the build method and then saved const newItem = Item.build({ itemName, }); diff --git a/examples_new/microservices/items/src/index.ts b/examples_new/microservices/items/src/index.ts index 1e2c41b7f..f1db87fe0 100644 --- a/examples_new/microservices/items/src/index.ts +++ b/examples_new/microservices/items/src/index.ts @@ -3,7 +3,6 @@ import mongoose from 'mongoose'; import { app } from './app'; import { DbConnectionError } from '@chronosrx/common'; import { Item } from './models/items'; -import { User } from './models/users'; import dotenv from 'dotenv'; dotenv.config({ path: path.resolve(__dirname + '../../.env') }); @@ -19,7 +18,6 @@ const start = async () => { console.log('🍃 Connected to MongoDB'); // reset DB's - await User.deleteMany(); await Item.deleteMany(); } catch (err) { throw new DbConnectionError(); diff --git a/examples_new/microservices/items/src/models/users.ts b/examples_new/microservices/items/src/models/users.ts deleted file mode 100644 index bb91e7f37..000000000 --- a/examples_new/microservices/items/src/models/users.ts +++ /dev/null @@ -1,48 +0,0 @@ -import mongoose from 'mongoose'; - -//define attrs -interface UserAttrs { - username: string; - userId: string; -} -// add a method 'build' to the UserModel -// mongoose has built-in Model class that takes 'UserDoc' -interface UserModel extends mongoose.Model { - build(attrs: UserAttrs): UserDoc; -} -//create user data in the database in this shape -interface UserDoc extends mongoose.Document { - username: string; -} -//create the Schema in mongoose with defined requirements -const userSchema = new mongoose.Schema( - { - username: { - type: String, - required: true, - unique: true, - }, - }, - { - //anytime we create Json formatted data, transform the user document as following - toJSON: { - transform(doc, ret) { - ret.id = ret._id; - delete ret._id; - delete ret.__v; - }, - }, - } -); - -userSchema.statics.build = (attrs: UserAttrs) => { - //returning user document with (attrs) passed in - return new User({ - _id: attrs.userId, - username: attrs.username, - }); -}; - -const User = mongoose.model('User', userSchema); - -export { User };