async findUserArticles(IdUser: string) {
const userRepository = this.dataSource.getRepository(User);
return await userRepository.find(
{
where: {
IdUser: IdUser
},
relations: {
Articles: true
}
});
}
async findUserArticle(IdUser: string, IdArticle: number) {
const userRepository = this.dataSource.getRepository(User);
return await userRepository.findOne(
{
where: {
IdUser: IdUser,
Articles: {
IdArticle: IdArticle
}
},
relations: {
Articles: true
}
});
}
ArticleController.post('/Article/saveUserArticle', (req, res) => {
if (req.body == null)
{
res.status(400).send({status:"body error"});
return;
}
let idUser:string = req.body.IdUser;
let article:Article = req.body.IdArticle;
if (idUser == null || article == null)
{
res.status(400).send({status:"body error"});
return;
}
userDao.findUser(idUser).then((users: Array<User>) => {
if (users.length > 1)
{
article.user = users[0];
articleDao.saveArticle(req.body).then((data: any) => {
res.status(200).send({status:"article save OK"});
});
}
else
{
res.status(400).send({status:"user not found"});
}
}).catch((error:any) => {
res.status(400).send({status:"user not found"});
});
});