Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async getAuthenticatedUser(
@inject('userId') userId: number,
): Promise {
if (userId !== 42) {
// using "return Promise.reject(err)" would be probably faster
// (a possible micro-optimization)
throw new HttpErrors.NotFound('Current user not found (?!).');
}
return new UserResponse({
id: userId,
name: 'Admin',
email: 'admin@example.com',
});
}
async get(
@param.path.string('userId') userId: string,
): Promise {
debug('Get shopping cart %s', userId);
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;
}
}