Skip to content

Commit

Permalink
feat: municipality full name for user reconciliation
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudambro committed Jan 30, 2024
1 parent 2b4c4fc commit f54f795
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "municipality_full_name" TEXT;
1 change: 1 addition & 0 deletions api-node/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ model User {
appdevice String?
municipality_insee_code String? // code INSEE
municipality_name String?
municipality_full_name String?
municipality_zip_code String?
push_notif_token String?
created_at DateTime @default(now())
Expand Down
30 changes: 14 additions & 16 deletions api-node/src/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ router.put(
z.object({
municipality_insee_code: z.string().optional(),
municipality_name: z.string().optional(),
municipality_full_name: z.string().optional(),
municipality_zip_code: z.string().optional(),
push_notif_token: z.string().optional(),
favorite_indicator: z.string().optional(),
Expand Down Expand Up @@ -82,6 +83,9 @@ router.put(
if (bodyHasProperty('municipality_name')) {
updatedUser.municipality_name = req.body.municipality_name;
}
if (bodyHasProperty('municipality_full_name')) {
updatedUser.municipality_full_name = req.body.municipality_full_name;
}
if (bodyHasProperty('municipality_zip_code')) {
updatedUser.municipality_zip_code = req.body.municipality_zip_code;
}
Expand All @@ -105,22 +109,16 @@ router.put(
req.body.notifications_preference;
}

await prisma.user
.upsert({
where: { matomo_id: req.user.matomo_id },
update: updatedUser,
create: {
matomo_id: req.user.matomo_id,
...updatedUser,
},
})
.then(() => {
console.log('User has been updated');
})
.catch((error) => {
console.log('error', error);
});
res.status(200).send({ ok: true });
const updatedDbUser = await prisma.user.upsert({
where: { matomo_id: req.user.matomo_id },
update: updatedUser,
create: {
matomo_id: req.user.matomo_id,
...updatedUser,
},
});

res.status(200).send({ ok: true, data: updatedDbUser });
},
),
);
Expand Down

0 comments on commit f54f795

Please sign in to comment.