Skip to content

Commit

Permalink
changed client profile update structure for FE
Browse files Browse the repository at this point in the history
  • Loading branch information
sajjanstha committed Jan 31, 2024
1 parent e5dab64 commit 4bb2a99
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
20 changes: 11 additions & 9 deletions src/app/api/client-profile-updates/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,19 @@ export async function GET(request: NextRequest) {
const client = clientLookup[update.clientId];
const company = companyLookup[update.companyId];

const customFields = portalCustomFields.data?.map((portalCustomField) => {
let parsedClientProfileUpdate: ParsedClientProfileUpdatesResponse = {
id: update.id,
client: getClientDetails(client),
company: getCompanyDetails(company),
lastUpdated: update.createdAt,
};

portalCustomFields.data?.forEach((portalCustomField) => {
const value = update.customFields[portalCustomField.key] ?? null;
const options = getSelectedOptions(portalCustomField, value);

return {
// @ts-ignore
parsedClientProfileUpdate[portalCustomField.name] = {
name: portalCustomField.name,
type: portalCustomField.type,
key: portalCustomField.key,
Expand All @@ -83,13 +91,7 @@ export async function GET(request: NextRequest) {
};
});

return {
id: update.id,
client: getClientDetails(client),
company: getCompanyDetails(company),
lastUpdated: update.createdAt,
customFields,
};
return parsedClientProfileUpdate;
});

return NextResponse.json(parsedClientProfileUpdates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export class ClientProfileUpdatesService {
WHERE "clientId" = ${clientId}::uuid
AND "createdAt" <= ${lastUpdated}
AND "changedFields" ->> ${customFieldKey} IS NOT NULL
ORDER BY "createdAt" DESC;
ORDER BY "createdAt" DESC
LIMIT 5;
`;
}
}
1 change: 0 additions & 1 deletion src/types/clientProfileUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const ParsedClientProfileUpdatesResponseSchema = z.object({
iconImageUrl: z.string().nullable(),
}),
lastUpdated: z.date(),
customFields: z.unknown(),
});
export type ParsedClientProfileUpdatesResponse = z.infer<typeof ParsedClientProfileUpdatesResponseSchema>;

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3740,7 +3740,7 @@ neo-async@^2.6.2:
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==

next@^14.0.2, next@latest:
next@14.1.0, next@^14.0.2:
version "14.1.0"
resolved "https://registry.yarnpkg.com/next/-/next-14.1.0.tgz#b31c0261ff9caa6b4a17c5af019ed77387174b69"
integrity sha512-wlzrsbfeSU48YQBjZhDzOwhWhGsy+uQycR8bHAOt1LY1bn3zZEcDyHQOEoN3aWzQ8LHCAJ1nqrWCc9XF2+O45Q==
Expand Down

0 comments on commit 4bb2a99

Please sign in to comment.