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 getRepository(Todo).findOne({ id: +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 getRepository(Todo).remove(todo);
// Returns an successful empty response. The status is 204.
return new HttpResponseNoContent();
}
const todo = await getRepository(Todo).findOne({
id: +ctx.request.params.id,
// Do not return the todo if it does not belong to the current user.
owner: ctx.user
});
// Return a 404 Not Found response if no such todo exists.
if (!todo) {
return new HttpResponseNotFound();
}
// Remove the todo from the database.
await getRepository(Todo).remove(todo);
// Returns an successful empty response. The status is 204.
return new HttpResponseNoContent();
}
async logout(ctx: Context) {
const response = new HttpResponseNoContent();
await this.store.destroy(ctx.session.sessionID);
removeSessionCookie(response);
return new HttpResponseNoContent();
}
logout(ctx: Context) {
logOut(ctx);
return new HttpResponseNoContent();
}
async deleteById(ctx: Context) {
const testFooBar = await getRepository(TestFooBar).findOne(ctx.request.params.testFooBarId);
if (!testFooBar) {
return new HttpResponseNotFound();
}
await getRepository(TestFooBar).delete(ctx.request.params.testFooBarId);
return new HttpResponseNoContent();
}
async deleteById(ctx: Context) {
const testFooBar = await getRepository(TestFooBar).findOne(ctx.request.params.testFooBarId);
if (!testFooBar) {
return new HttpResponseNotFound();
}
await getRepository(TestFooBar).delete(ctx.request.params.testFooBarId);
return new HttpResponseNoContent();
}
bar() {
return new HttpResponseNoContent();
}
async login(ctx: Context) {
const user = await getRepository(User).findOne({ email: ctx.request.body.email });
if (!user) {
return new HttpResponseUnauthorized();
}
if (!await verifyPassword(ctx.request.body.password, user.password)) {
return new HttpResponseUnauthorized();
}
const session = await this.store.createAndSaveSessionFromUser(user);
const response = new HttpResponseNoContent();
const token = session.getToken();
setSessionCookie(response, token);
return response;
}
async logout(ctx: Context) {
await this.store.destroy(ctx.session.sessionID);
const response = new HttpResponseNoContent();
removeSessionCookie(response);
return response;
}
}
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();
}