Atualizando backend de usuários para conter informações de contato

This commit is contained in:
Matheus Albino Brunhara
2022-06-19 22:20:30 -05:00
parent 0d2b7a6884
commit 01a30b0f17
11 changed files with 133 additions and 56 deletions

View File

@@ -3,30 +3,35 @@ import { getRepository } from 'typeorm';
import AppError from '../errors/AppError';
import User from '../models/User';
import Social from '../models/Social';
import Social from '../models/SocialInformation';
class FindUserSocialService {
public async execute(id_user: string): Promise<Social> {
const usersRepository = getRepository(User);
const socialRepository = getRepository(Social);
const socialInformationRepository = getRepository(Social);
const user = await usersRepository.findOne({
where: { id_user }
});
if (!user) {
// TODO, fazer no front um tratamento para isso
throw new AppError('User does not exist.');
};
const social = await socialRepository.findOne({
let social = await socialInformationRepository.findOne({
where: { user },
});
if (!social) {
// TODO, lembrar
// muito importate colocar o código HTTP de erro
throw new AppError('User does not have social information.', 200);
social = socialInformationRepository.create({
user,
phone: '',
whatsapp: '',
facebook: '',
telegram: '',
});
await socialInformationRepository.save(social);
};
return social;