Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getProduct(id: number) {
const product = this.products.find((product) => {
return product._id === id;
});
if (!product) {
//nestjs對於http exception有API可以調用,建議使用。
throw new HttpException("product not found", 404);
}
return Promise.resolve(product);
}
//在nestjs也是可以歡樂使用Rx.js
"SELECT * FROM user WHERE email = ?", [email], (err, user) => {
if(err) {
return reject(new HttpException(err, 503))
}
else {
if(user.length === 0) {
return reject(new HttpException("User does not exist", 401))
}
else {
if (password != user[0].password) {
return reject(new HttpException("Incorrect password", 401))
}
else {
return resolve(this.authHelper.genToken(user[0]));
}
}
}
});
async transform(value: string, metadata: ArgumentMetadata) {
const val = parseInt(value, 10);
if (isNaN(val)) {
throw new HttpException('Validation failed', HttpStatus.BAD_REQUEST);
} else if (val <= 0) {
throw new HttpException('Validation failed', HttpStatus.BAD_REQUEST);
}
return val;
}
}
return stream$.catch(err => Observable.throw(new HttpException('Exception interceptor message', HttpStatus.BAD_GATEWAY)));
}
getUser(id: number) {
const user = this.users.find((user) => {
return user._id === id;
});
if (!user) {
//nestjs對於http exception有API可以調用,建議使用。
throw new HttpException("user not found", 404);
}
return Promise.resolve(user);
}
//在nestjs也是可以歡樂使用Rx.js
async transform(value: string, metadata: ArgumentMetadata) {
const val = parseInt(value, 10);
if (isNaN(val)) {
throw new HttpException('檢驗錯誤', HttpStatus.BAD_REQUEST);
}
return val;
}
}
public login(email, password) {
if(!email){
return(new HttpException("Email is required", 422))
}
if(!password){
return(new HttpException("Password is required", 422))
}
return new Promise((resolve, reject) => {
db.all(
"SELECT * FROM user WHERE email = ?", [email], (err, user) => {
if(err) {
return reject(new HttpException(err, 503))
}
else {
if(user.length === 0) {
return reject(new HttpException("User does not exist", 401))
}
else {
if (password != user[0].password) {
"VALUES (?, ?, ?, ?, 'user')", [uuid.v1().replace(/-/g, ""), username, email, password], (err) => {
return !err ?
resolve({'message':'User has been registered'}) :
reject(new HttpException(err, 500));
});
});