Skip to content

Commit

Permalink
Refactor: delete client profile logic to delete mood track and chat data
Browse files Browse the repository at this point in the history
  • Loading branch information
georgiganchev-7DIGIT committed Jan 3, 2024
1 parent 09609ee commit fa55635
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions service/controllers/clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getClientCampaignConsultationsQuery,
getTotalCampaignConsultationsQuery,
deleteChatHistoryQuery,
deleteMoodTrackDataQuery,
} from "#queries/clients";

import {
Expand Down Expand Up @@ -118,6 +119,7 @@ export const deleteClientData = async ({
image,
password,
userPassword,
time,
}) => {
const validatePassword = await bcrypt.compare(password, userPassword);

Expand All @@ -134,6 +136,15 @@ export const deleteClientData = async ({
if (res.rowCount === 0) {
throw clientNotFound(language);
} else {
await deleteChatHistoryQuery({
poolCountry: country,
client_detail_id: client_id,
time,
});
await deleteMoodTrackDataQuery({
poolCountry: country,
client_detail_id: client_id,
});
if (image !== "default") {
try {
const s3 = new AWS.S3({
Expand Down
14 changes: 14 additions & 0 deletions service/queries/clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,17 @@ export const deleteChatHistoryQuery = async ({
[client_detail_id, time]
);
};

export const deleteMoodTrackDataQuery = async ({
poolCountry,
client_detail_id,
}) => {
return await getDBPool("clinicalDb", poolCountry).query(
`
UPDATE mood_tracker
SET comment = 'DELETED', mood = 'DELETED'
WHERE client_detail_id = $1;
`,
[client_detail_id]
);
};
1 change: 1 addition & 0 deletions service/schemas/clientSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const deleteClientDataSchema = yup.object().shape({
image: yup.string().required(),
userPassword: yup.string().required(),
password: yup.string().required(),
time: yup.string().required(),
});

export const updateClientImageSchema = yup.object().shape({
Expand Down

0 comments on commit fa55635

Please sign in to comment.