Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async deleteTodo(ctx: Context) {
// Get the todo with the id given in the URL if it exists.
const todo = await Todo.findById(ctx.request.params.id);
// Return a 404 Not Found response if no such todo exists.
if (!todo) {
return new HttpResponseNotFound();
}
// Remove the todo from the database.
await Todo.findByIdAndRemove(ctx.request.params.id);
// Returns an successful empty response. The status is 204.
return new HttpResponseNoContent();
}
async putById(ctx: Context) {
const testFooBar = await getRepository(TestFooBar).findOne(ctx.request.params.testFooBarId);
if (!testFooBar) {
return new HttpResponseNotFound();
}
Object.assign(testFooBar, ctx.request.body);
await getRepository(TestFooBar).save(testFooBar);
return new HttpResponseOK(testFooBar);
}
renderApp(ctx: Context) {
if (!ctx.request.accepts('html')) {
return new HttpResponseNotFound();
}
return createHttpResponseFile({
directory: './src/examples/frontend-integration/public',
file: 'index.html'
});
}
}
async putById(ctx: Context) {
const testFooBar = await getRepository(TestFooBar).findOne(ctx.request.params.testFooBarId);
if (!testFooBar) {
return new HttpResponseNotFound();
}
Object.assign(testFooBar, ctx.request.body);
await getRepository(TestFooBar).save(testFooBar);
return new HttpResponseOK(testFooBar);
}
async patchById(ctx: Context) {
const testFooBar = await getRepository(TestFooBar).findOne(ctx.request.params.testFooBarId);
if (!testFooBar) {
return new HttpResponseNotFound();
}
Object.assign(testFooBar, ctx.request.body);
await getRepository(TestFooBar).save(testFooBar);
return new HttpResponseOK(testFooBar);
}
notFound() {
return new HttpResponseNotFound('The page your are looking for does not exist');
}
}
async patchById(ctx: Context) {
const testFooBar = await getRepository(TestFooBar).findOne(ctx.request.params.testFooBarId);
if (!testFooBar) {
return new HttpResponseNotFound();
}
Object.assign(testFooBar, ctx.request.body);
await getRepository(TestFooBar).save(testFooBar);
return new HttpResponseOK(testFooBar);
}
async patchById(ctx: Context) {
const product = await getRepository(Product).findOne(ctx.request.params.id);
if (!product) {
return new HttpResponseNotFound();
}
Object.assign(product, ctx.request.body);
await getRepository(Product).save(product);
return new HttpResponseOK(product);
}
async deleteById(ctx: Context) {
const product = await getRepository(Product).findOne(ctx.request.params.id);
if (!product) {
return new HttpResponseNotFound();
}
await getRepository(Product).delete(ctx.request.params.id);
return new HttpResponseNoContent();
}
async putById(ctx: Context) {
const product = await getRepository(Product).findOne(ctx.request.params.id);
if (!product) {
return new HttpResponseNotFound();
}
Object.assign(product, ctx.request.body);
await getRepository(Product).save(product);
return new HttpResponseOK(product);
}