Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* Get product by Id
* @param productId Product Id
*/
@Get(`{productId}`)
public Get(productId: string): Promise {
// @ts-ignore
let product = Product.findOne({ _id: productId }).exec()
return Promise.resolve(product)
}
/**
* Create a product
* @param request This is a product creation request description
*/
@Post()
public Create(@Body() request: ProductCreateRequest): Promise {
let product = new Product({ _id: uuid.v1(), ...request })
console.log(product)
let result = Product.create(product)
return Promise.resolve(result)
}
}
declare var require: any
var uuid = require('uuid')
import { Route, Get, Post, Put, Body, Response } from 'tsoa'
import { default as Rating, RatingCreateRequest, RatingUpdateRequest } from '../models/rating'
@Route(`api/ratings`)
export class RatingController {
/**
* Get the all ratings
*/
@Get()
public async GetAll(): Promise {
// @ts-ignore
var ratings = await Rating.find({}).exec()
var result = []
ratings.reduce(function (res, value) {
if (!res[value.productId]) {
res[value.productId] = {
productId: value.productId,
cost: 0,
userId: value.userId,
/* tslint:disable */
import { Controller, ValidationService, FieldErrors, ValidateError, TsoaRoute } from 'tsoa';
import { WidgetsController } from './controllers/widgets-controller';
import * as express from 'express';
const models: TsoaRoute.Models = {
"IWidget": {
"properties": {
"id": { "dataType": "double", "required": true },
"label": { "dataType": "string", "required": true },
"color": { "dataType": "string", "required": true },
},
},
};
const validationService = new ValidationService(models);
export function RegisterRoutes(app: express.Express) {
app.get('/api/widgets',
function(request: any, response: any, next: any) {
const args = {
};
let validatedArgs: any[] = [];
try {
validatedArgs = getValidatedArgs(args, request);
} catch (err) {
return next(err);
}
const controller = new WidgetsController();
* Create a rating
* @param request This is a rating creation request description
*/
@Post()
public async Create(@Body() request: RatingCreateRequest): Promise {
console.info(request)
let rating = new Rating({ _id: uuid.v1(), ...request })
let result = await Rating.create(rating)
return Promise.resolve(result)
}
/**
* Update a rating
* @param request This is a rating update request description
*/
@Put()
public async Update(@Body() request: RatingUpdateRequest): Promise {
let rating = await Rating.findOne({ productId: request.productId, userId: request.userId }).exec() || {}
if (!rating) return Promise.reject("Could not find a Product or User")
rating = { rating, ...request }
let result = await Rating.update(rating)
return Promise.resolve(result)
}
}