Julian
06/09/2021, 11:11 AMpassword is removed and replaced with hashedPassword, a nested profile is created and inside profile an address is created?
{
"email": "<mailto:test@test.nl|test@test.nl>",
"password": "abcd",
"profile": {
"firstName": "Test",
"lastName": "T",
"address": {
"street": "A",
"zipcode": "B",
"city": "C",
"state": "D",
"country": "E"
}
}
}
Because it seems like a bit of a pain to manually map every field to an object that can be used for a create query functionRyan
06/09/2021, 11:26 AMRyan
06/09/2021, 11:28 AMJulian
06/09/2021, 11:30 AMprofile: {
create: { ... }
}
and then the same has to be done inside of that for the address, correct?Julian
06/09/2021, 11:30 AMcreateRyan
06/09/2021, 11:31 AMcreate would be required.Ryan
06/09/2021, 11:31 AMcreate.Julian
06/09/2021, 11:33 AMJulian
06/09/2021, 11:35 AMconst userInData: any = { ...userIn };
delete userInData.password;
delete userInData.profile;
console.log(userIn.password);
const hashedPassword = await this._authService.hashPassword(
userIn.password
);
let data: Prisma.UserCreateInput = {
...userInData,
hashedPassword: hashedPassword,
};
if (userIn.profile) {
const profileData: any = { ...userIn.profile };
delete profileData.address;
data.profile = {
create: { ...profileData },
};
}
console.log(data);
const user = this._prismaService.user.create({ data: data });
results in this:
{
email: '<mailto:test@test.nl|test@test.nl>',
hashedPassword: '$2b$10$DaabkBHuBxpwG59eOMAePeU7BmpsJ56tnwmtmgp1GS/8Y7HMQf.zS',
profile: {
create: {
firstName: 'Test',
lastName: 'T',
phoneNumber: undefined,
dateOfBirth: undefined
}
}
}Julian
06/09/2021, 11:36 AM