Italo Gama
08/16/2022, 2:52 PMMichael Jay
08/16/2022, 3:01 PMNathan Froese
08/16/2022, 3:33 PMItalo Gama
08/16/2022, 4:17 PMItalo Gama
08/16/2022, 4:17 PMexport class CreateUserInput {
@IsString()
@IsNotEmpty({ message: âCampo Nome nĂŁo pode estar vazio.â }) // required
@Field(() => _String_)
first_name: _string_;
@IsString()
@IsNotEmpty({ message: âCampo Sobrenome nĂŁo pode estar vazio.â })
@Field(() => _String_)
last_name: _string_;
@IsString()
@IsNotEmpty({ message: âCampo Username nĂŁo pode estar vazio.â })
@Field(() => _String_)
username: _string_;
@IsString()
@IsNotEmpty({ message: âCampo Senha nĂŁo pode estar vazio.â }) // required
@Field(() => _String_)
password: _string_;
@IsDate()
@Field(() => _Date_)
birth_date: _Date_;
@IsString()
@Field(() => _String_)
phone: _string_;
@IsInt()
@IsNotEmpty({ message: âCampo Senha nĂŁo pode estar vazio.â }) // required
@Field(() => _Int_)
active: _number_;
@IsEnum(_gender_type_)
@IsNotEmpty({ message: âCampo Senha nĂŁo pode estar vazio.â }) // required
@Field(() => _gender_type_)
gender: _gender_type_;
@IsString()
@IsNotEmpty({ message: âCampo CPF nĂŁo pode estar vazio.â }) // required
@Field(() => _String_)
cpf: _string_;
@IsString()
@IsNotEmpty({ message: âCampo CPF nĂŁo pode estar vazio.â }) // required
@Field(() => _String_)
rg: _string_;
@IsDate()
@IsNotEmpty()
@Field(() => _Date_)
created_at: _Date_;
@IsDate()
@IsNotEmpty()
@Field(() => _Date_)
updated_at: _Date_;
@IsString()
@Field(() => _String_)
photo: _string_;
@IsEnum(_scholarity_type_)
@IsNotEmpty({ message: âCampo Senha nĂŁo pode estar vazio.â }) // required
@Field(() => _scholarity_type_)
scholarity: _scholarity_type_;
@IsString()
@Field(() => _String_)
academic_formation: _string_;
@IsString()
@Field(() => _String_)
profession: _string_;
@IsString()
@Field(() => _String_)
company_work: _string_;
@IsBoolean()
@Field(() => _Boolean_)
baptized: _boolean_;
@IsDate()
@Field(() => _Date_)
baptism_date: _Date_;
@IsDate()
@Field(() => _Date_)
marriage_date: _Date_;
@IsDate()
@Field(() => _Date_)
member_since: _Date_;
@IsEnum(_reason_entry_type_)
@IsNotEmpty({ message: âCampo Senha nĂŁo pode estar vazio.â }) // required
@Field(() => _reason_entry_type_)
reason_entry: _reason_entry_type_;
@IsString()
@Field(() => _String_)
former_religion: _string_;
@IsString()
@Field(() => _String_)
belonged_church: _string_;
@IsString()
@Field(() => _String_)
natural_from: _string_;
@IsString()
@Field(() => _String_)
nationality: _string_;
@IsString()
@Field(() => _String_)
ministry: _string_;
@IsBoolean()
@Field(() => _Boolean_)
cursillo: _boolean_;
@IsDate()
@Field(() => _Date_)
cursillo_date: _Date_;
@IsString()
@Field(() => _String_)
cursillo_leaders: _string_;
@IsBoolean()
@Field(() => _Boolean_)
ecc: _boolean_;
@IsDate()
@Field(() => _Date_)
ecc_date: _Date_;
@IsString()
@Field(() => _String_)
ecc_leaders: _string_;
@IsBoolean()
@Field(() => _Boolean_)
ywc: _boolean_;
@IsDate()
@Field(() => _Date_)
ywc_date: _Date_;
@IsString()
@Field(() => _String_)
ywc_leaders: _string_;
@IsNumber()
@Field(() => _Int_)
@IsEmpty()
spouse_id?: _number_;
@Field(_type_ => CreateAddressInput)
address?: CreateAddressInput;
}Italo Gama
08/16/2022, 4:18 PMItalo Gama
08/16/2022, 4:18 PMasync create(_data_: CreateUserInput): _Promise_<UsersOutput> {
//look if user already exist...
const userExist = await _this_.findByEmail(_data_.username);
if (userExist) {
throw *new* HttpException('User already exist.', _HttpStatus_.BAD_REQUEST);
}
//look if cpf already exist...
const cpfExist = await _this_.findByCPF(_data_.cpf);
if (cpfExist) {
throw *new* HttpException('CPF already registered.', _HttpStatus_.BAD_REQUEST);
}
try {
const hashedPass = hashPasswordTransform.to(_data_.password);
const response = await _this_.prisma.users.create({
data: {
username: _data_.username,
first_name: _data_.first_name,
last_name: _data_.last_name,
phone: _data_.phone,
password: hashedPass,
birth_date: _data_.birth_date,
active: _data_.active,
gender: _data_.gender,
cpf: _data_.cpf,
rg: _data_.rg,
photo: _data_.photo,
scholarity: _data_.scholarity,
academic_formation: _data_.academic_formation,
profession: _data_.profession,
company_work: _data_.company_work,
baptized: _data_.baptized,
baptism_date: _data_.baptism_date,
marriage_date: _data_.marriage_date,
member_since: _data_.member_since,
reason_entry: _data_.reason_entry,
former_religion: _data_.former_religion,
belonged_church: _data_.belonged_church,
natural_from: _data_.natural_from,
nationality: _data_.nationality,
ministry: _data_.ministry,
cursillo: _data_.cursillo,
cursillo_date: _data_.cursillo_date,
cursillo_leaders: _data_.cursillo_leaders,
ecc: _data_.ecc,
ecc_date: _data_.ecc_date,
ecc_leaders: _data_.ecc_leaders,
ywc: _data_.ywc,
ywc_date: _data_.ywc_date,
ywc_leaders: _data_.ywc_leaders,
created_at: _data_.created_at,
updated_at: _data_.updated_at,
spouse_id: 1,
address: {
create: {
street : _data_.address.street,
number: _data_.address.number,
neighborhood: _data_.address.neighborhood,
city: _data_.address.city,
zipcode: _data_.address.zipcode,
complement: _data_.address.complement,
state: _data_.address.state,
created_at: _data_.address.created_at,
updated_at: _data_.address.updated_at
},
},
},
});
if (response) {
return {
users: response
};
}
return {
error: {
code: _ErrorsTypes_.USER_NOT_CREATED,
message: âOps, User was not created.â
}
};
} catch (error) {
throw *new* HttpException('Error creating User', _HttpStatus_.BAD_REQUEST);
}
}Italo Gama
08/16/2022, 4:20 PMMichael Jay
08/16/2022, 5:49 PMasync create(data: CreateUserInput): Promise<UsersOutput> {
//look if user already exist...
const userExist = await this.findByEmail(data.username);
if (userExist) {
throw new HttpException('User already exist.', HttpStatus.BAD_REQUEST);
}
//look if cpf already exist...
const cpfExist = await this.findByCPF(data.cpf);
if (cpfExist) {
throw new HttpException('CPF already registered.', HttpStatus.BAD_REQUEST);
}
try {
const hashedPass = <http://hashPasswordTransform.to|hashPasswordTransform.to>(data.password);
const response = await this.prisma.users.create({
data: {
username: data.username,
first_name: data.first_name,
last_name: data.last_name,
phone: data.phone,
password: hashedPass,
birth_date: data.birth_date,
active: data.active,
gender: data.gender,
cpf: data.cpf,
rg: data.rg,
photo: data.photo,
scholarity: data.scholarity,
academic_formation: data.academic_formation,
profession: data.profession,
company_work: data.company_work,
baptized: data.baptized,
baptism_date: data.baptism_date,
marriage_date: data.marriage_date,
member_since: data.member_since,
reason_entry: data.reason_entry,
former_religion: data.former_religion,
belonged_church: data.belonged_church,
natural_from: data.natural_from,
nationality: data.nationality,
ministry: data.ministry,
cursillo: data.cursillo,
cursillo_date: data.cursillo_date,
cursillo_leaders: data.cursillo_leaders,
ecc: data.ecc,
ecc_date: data.ecc_date,
ecc_leaders: data.ecc_leaders,
ywc: data.ywc,
ywc_date: data.ywc_date,
ywc_leaders: data.ywc_leaders,
created_at: data.created_at,
updated_at: data.updated_at,
spouse_id: 1,
address: {
create: {
street : data.address.street,
number: data.address.number,
neighborhood: data.address.neighborhood,
city: data.address.city,
zipcode: data.address.zipcode,
complement: data.address.complement,
state: data.address.state,
created_at: data.address.created_at,
updated_at: data.address.updated_at
},
},
},
});
if (response) {
return {
users: response
};
}
return {
error: {
code: ErrorsTypes.USER_NOT_CREATED,
message: 'Ops, User was not created.'
}
};
} catch (error) {
throw new HttpException('Error creating User', HttpStatus.BAD_REQUEST);
}
}
Michael Jay
08/16/2022, 5:49 PMItalo Gama
08/16/2022, 5:58 PMItalo Gama
08/16/2022, 5:58 PMMichael Jay
08/16/2022, 6:11 PMdata
, and I would try to explicitly type it to what you want it to be. That Without<...> seems weird. I can't be certain, but I'd guess it's not supposed to include spouse_id and that's why you're seeing that error.Italo Gama
08/16/2022, 11:53 PMMichael Jay
08/17/2022, 8:23 PMspouse_id: typeof data.spouse_id === "number" ? spouse_id : 0
This is a general idea, not the exact solution to your problem. Hope it helps.Michael Jay
08/17/2022, 8:36 PMif (typeof newEmail.email !== "string") throw new InternalServerErrorException()
Michael Jay
08/17/2022, 8:37 PMItalo Gama
08/17/2022, 8:37 PMItalo Gama
08/17/2022, 11:26 PMAustin
08/30/2022, 7:09 PMschema.prisma
?