Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'204': {description: `${modelName} was updated`},
},
})
async updateById(
@param(idPathParam) id: IdType,
@body(modelCtor, {partial: true}) data: Partial,
): Promise {
await this.repository.updateById(
id,
// FIXME(bajtos) Improve repository API to support this use case
// with no explicit type-casts required
data as DataObject,
);
}
@put('/{id}', {
responses: {
'204': {description: `${modelName} was updated`},
},
})
async replaceById(
@param(idPathParam) id: IdType,
@body(modelCtor) data: T,
): Promise {
await this.repository.replaceById(id, data);
}
@del('/{id}', {
responses: {
'204': {description: `${modelName} was deleted`},
},
})
type: 'array',
items: getModelSchemaRef(Todo, {includeRelations: true}),
},
},
},
},
},
})
async findTodos(
@param.query.object('filter', getFilterSchemaFor(Todo))
filter?: Filter,
): Promise {
return this.todoRepo.find(filter);
}
@put('/todos/{id}', {
responses: {
'204': {
description: 'Todo PUT success',
},
},
})
async replaceTodo(
@param.path.number('id') id: number,
@requestBody() todo: Todo,
): Promise {
await this.todoRepo.replaceById(id, todo);
}
@patch('/todos/{id}', {
responses: {
'204': {
responses: {
'204': {
description: 'AuditLog PATCH success',
},
},
})
async updateById(
@param.path.number('id') id: number,
@requestBody() auditLog: AuditLog,
): Promise {
await this.auditLogRepository.updateById(id, auditLog);
}
@authenticate(STRATEGY.BEARER)
@authorize([PermissionKey.UpdateAudit])
@put('/audit-logs/{id}', {
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}', {
})
async updateById(
@param.path.number('id') id: number,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Note, {partial: true}),
},
},
})
note: Partial,
): Promise {
await this.noteRepository.updateById(id, note);
}
@put('/notes/{id}', {
responses: {
'204': {
description: 'Note PUT success',
},
},
})
async replaceById(
@param.path.number('id') id: number,
@requestBody() note: Note,
): Promise {
await this.noteRepository.replaceById(id, note);
}
@del('/notes/{id}', {
responses: {
'204': {
responses: {
'204': {
description: 'Role PATCH success',
},
},
})
async updateById(
@param.path.number('id') id: number,
@requestBody() role: Role,
): Promise {
await this.roleRepository.updateById(id, role);
}
@authenticate(STRATEGY.BEARER)
@authorize([PermissionKey.UpdateRole])
@put('/roles/{id}', {
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: 'Tenant PATCH success',
},
},
})
async updateById(
@param.path.number('id') id: number,
@requestBody() tenant: Tenant,
): Promise {
await this.tenantRepository.updateById(id, tenant);
}
@authenticate(STRATEGY.BEARER)
@authorize([PermissionKey.UpdateTenant])
@put('/tenants/{id}', {
responses: {
'204': {
description: 'Tenant PUT success',
},
},
})
async replaceById(
@param.path.number('id') id: number,
@requestBody() tenant: Tenant,
): Promise {
await this.tenantRepository.replaceById(id, tenant);
}
@authenticate(STRATEGY.BEARER)
@authorize([PermissionKey.DeleteTenant])
@del('/tenants/{id}', {
content: {
'application/json': {
schema: {type: 'array', items: getModelSchemaRef(Todo)},
},
},
},
},
})
async findTodos(
@param.query.object('filter', getFilterSchemaFor(Todo))
filter?: Filter,
): Promise {
return this.todoRepo.find(filter);
}
@put('/todos/{id}', {
responses: {
'204': {
description: 'Todo PUT success',
},
},
})
async replaceTodo(
@param.path.number('id') id: number,
@requestBody() todo: Todo,
): Promise {
await this.todoRepo.replaceById(id, todo);
}
@patch('/todos/{id}', {
responses: {
'204': {
/**
* Controller for shopping cart
*/
export class ShoppingCartController {
constructor(
@repository(ShoppingCartRepository)
public shoppingCartRepository: ShoppingCartRepository,
) {}
/**
* Create or update the shopping cart for a given user
* @param userId User id
* @param cart Shopping cart
*/
@put('/shoppingCarts/{userId}', {
responses: {
'204': {
description: 'User shopping cart is created or updated',
},
},
})
async set(
@param.path.string('userId') userId: string,
@requestBody({description: 'shopping cart'}) cart: ShoppingCart,
): Promise {
debug('Create shopping cart %s: %j', userId, cart);
if (userId !== cart.userId) {
throw new HttpErrors.BadRequest(
`User id does not match: ${userId} !== ${cart.userId}`,
);
}
},
})
async updateById(
@param.path.number('id') id: number,
@requestBody() user: User,
): Promise {
await this.userRepository.updateById(id, user);
}
@authenticate(STRATEGY.BEARER)
@authorize([
PermissionKey.UpdateAnyUser,
PermissionKey.UpdateOwnUser,
PermissionKey.UpdateTenantUser,
])
@put('/users/{id}', {
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}', {