Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
})
async updateById(
@param.path.number('id') id: number,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(TodoList, {partial: true}),
},
},
})
todoList: Partial,
): Promise {
await this.todoListRepository.updateById(id, todoList);
}
@del('/todo-lists/{id}', {
responses: {
'204': {
description: 'TodoList DELETE success',
},
},
})
async deleteById(@param.path.number('id') id: number): Promise {
await this.todoListRepository.deleteById(id);
}
}
const cart = await this.shoppingCartRepository.get(userId);
debug('Shopping cart %s: %j', userId, cart);
if (cart == null) {
throw new HttpErrors.NotFound(
`Shopping cart not found for user: ${userId}`,
);
} else {
return cart;
}
}
/**
* Delete the shopping cart by user id
* @param userId User id
*/
@del('/shoppingCarts/{userId}', {
responses: {
'204': {
description: 'User shopping cart is deleted',
},
},
})
async remove(@param.path.string('userId') userId: string): Promise {
debug('Remove shopping cart %s', userId);
await this.shoppingCartRepository.delete(userId);
}
/**
* Add an item to the shopping cart for a given user
* @param userId User id
* @param cart Shopping cart item to be added
*/
responses: {
'204': {
description: 'Role PUT success',
},
},
})
async replaceById(
@param.path.number('id') id: number,
@requestBody() role: Role,
): Promise {
await this.roleRepository.replaceById(id, role);
}
@authenticate(STRATEGY.BEARER)
@authorize([PermissionKey.DeleteRole])
@del('/roles/{id}', {
responses: {
'204': {
description: 'Role DELETE success',
},
},
})
async deleteById(@param.path.number('id') id: number): Promise {
await this.roleRepository.deleteById(id);
}
}
})
@authenticate('jwt', {
required: [PermissionKey.ViewOwnUser, PermissionKey.UpdateOwnUser],
})
async updateSkill(@requestBody() skill: Skill): Promise {
const currentUser = await this.getCurrentUser();
await this.characterRepository.skill(currentUser.email).delete();
return await this.characterRepository
.skill(currentUser.email)
.create(skill);
}
/**
* delete weapon for current character
*/
@del('/updatecharacter/weapon', {
responses: {
'204': {
description: 'DELETE Weapon',
},
},
})
@authenticate('jwt', {
required: [PermissionKey.ViewOwnUser, PermissionKey.UpdateOwnUser],
})
async deleteWeapon(): Promise {
const currentUser = await this.getCurrentUser();
//unequip old weapon
let filter: Filter = {where: {characterId: currentUser.email}};
if ((await this.weaponRepository.find(filter))[0] != undefined) {
let oldWeapon: Weapon = await this.characterRepository
.weapon(currentUser.email)
description: 'Character PATCH success',
},
},
})
@authenticate('jwt', {"required": [PermissionKey.ViewAnyUser, PermissionKey.UpdateAnyUser]})
async updateById(
@param.query.string('email') email: string,
@requestBody() character: Character,
): Promise {
await this.characterRepository.updateById(email, character);
}
/**
* delete character by email
*/
@del('/admin/characters/{email}', {
responses: {
'204': {
description: 'Character DELETE success',
},
},
})
@authenticate('jwt', {"required": [PermissionKey.ViewAnyUser, PermissionKey.DeleteAnyUser]})
async deleteById(
@param.path.string('email') email: string
): Promise {
//delete weapon, armor, and skill
await this.characterRepository.weapon(email).delete();
await this.characterRepository.armor(email).delete();
await this.characterRepository.skill(email).delete();
///
await this.characterRepository.deleteById(email);
responses: {
'204': {
description: 'AuditLog PUT success',
},
},
})
async replaceById(
@param.path.number('id') id: number,
@requestBody() auditLog: AuditLog,
): Promise {
await this.auditLogRepository.replaceById(id, auditLog);
}
@authenticate(STRATEGY.BEARER)
@authorize([PermissionKey.DeleteAudit])
@del('/audit-logs/{id}', {
responses: {
'204': {
description: 'AuditLog DELETE success',
},
},
})
async deleteById(@param.path.number('id') id: number): Promise {
await this.auditLogRepository.deleteById(id);
}
}
.weapon(currentUser.email)
.get();
let char: Character = await this.characterRepository.findById(
currentUser.email,
);
char.attack! -= oldWeapon.attack;
char.defence! -= oldWeapon.defence;
await this.characterRepository.weapon(currentUser.email).delete();
await this.characterRepository.updateById(currentUser.email, char);
}
}
/**
* delete armor for current character
*/
@del('/updatecharacter/armor', {
responses: {
'204': {
description: 'DELETE Armor',
},
},
})
@authenticate('jwt', {
required: [PermissionKey.ViewOwnUser, PermissionKey.UpdateOwnUser],
})
async deleteArmor(): Promise {
const currentUser = await this.getCurrentUser();
//unequip old armor
let filter: Filter = {where: {characterId: currentUser.email}};
if ((await this.armorRepository.find(filter))[0] != undefined) {
let oldArmor: Armor = await this.characterRepository
.armor(currentUser.email)
async patch(
@param.path.number('id') id: number,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {partial: true}),
},
},
})
todo: Partial,
@param.query.object('where', getWhereSchemaFor(Todo)) where?: Where,
): Promise {
return this.todoListRepo.todos(id).patch(todo, where);
}
@del('/todo-lists/{id}/todos', {
responses: {
'200': {
description: 'TodoList.Todo DELETE success count',
content: {'application/json': {schema: CountSchema}},
},
},
})
async delete(
@param.path.number('id') id: number,
@param.query.object('where', getWhereSchemaFor(Todo)) where?: Where,
): Promise {
return this.todoListRepo.todos(id).delete(where);
}
}
responses: {
'204': {
description: 'User PUT success',
},
},
})
async replaceById(
@param.path.number('id') id: number,
@requestBody() user: User,
): Promise {
await this.userRepository.replaceById(id, user);
}
@authenticate(STRATEGY.BEARER)
@authorize([PermissionKey.DeleteAnyUser, PermissionKey.DeleteTenantUser])
@del('/users/{id}', {
responses: {
'204': {
description: 'User DELETE success',
},
},
})
async deleteById(@param.path.number('id') id: number): Promise {
await this.userRepository.deleteById(id);
}
}
.armor(currentUser.email)
.get();
let char: Character = await this.characterRepository.findById(
currentUser.email,
);
char.attack! -= oldArmor.attack;
char.defence! -= oldArmor.defence;
await this.characterRepository.armor(currentUser.email).delete();
await this.characterRepository.updateById(currentUser.email, char);
}
}
/**
* delete skill for current character
*/
@del('/updatecharacter/skill', {
responses: {
'204': {
description: 'DELETE Skill',
},
},
})
@authenticate('jwt', {
required: [PermissionKey.ViewOwnUser, PermissionKey.UpdateOwnUser],
})
async deleteSkill(): Promise {
const currentUser = await this.getCurrentUser();
await this.characterRepository.skill(currentUser.email).delete();
}
}