-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add field last submitted date to export API (#1514)
* update view submissions_data_vw to include submitteddate * changes to add submittedAt to the export API * updated query * renamed migration file --------- Co-authored-by: “bhuvan-aot” <“bhuvanesh.p@aot-technologies.com”>
- Loading branch information
1 parent
549ec85
commit 45a3ac6
Showing
4 changed files
with
116 additions
and
8 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
app/src/db/migrations/20241016164117__051_modify_submissions_data_vw.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
exports.up = function (knex) { | ||
return Promise.resolve() | ||
.then(() => knex.schema.dropViewIfExists('submissions_data_vw')) | ||
.then(() => | ||
knex.schema.raw(`CREATE OR REPLACE VIEW public.submissions_data_vw | ||
AS SELECT s."confirmationId", | ||
s."formName", | ||
s.version, | ||
s."createdAt", | ||
CASE | ||
WHEN u.id IS NULL THEN 'public'::character varying(255) | ||
ELSE u."fullName" | ||
END AS "fullName", | ||
CASE | ||
WHEN u.id IS NULL THEN 'public'::character varying(255) | ||
ELSE u.username | ||
END AS username, | ||
u.email, | ||
fs.submission -> 'data'::text AS submission, | ||
fs."updatedAt", | ||
fs."updatedBy", | ||
s.deleted, | ||
s.draft, | ||
s."submissionId", | ||
s."formId", | ||
s."formVersionId", | ||
u.id AS "userId", | ||
u."idpUserId", | ||
u."firstName", | ||
u."lastName", | ||
s."formSubmissionStatusCode" AS status, | ||
s."formSubmissionAssignedToFullName" AS assignee, | ||
s."formSubmissionAssignedToEmail" AS "assigneeEmail", | ||
fss."createdAt" AS "submittedAt" | ||
FROM submissions_vw s | ||
JOIN form_submission fs ON s."submissionId" = fs.id | ||
LEFT JOIN form_submission_user fsu ON s."submissionId" = fsu."formSubmissionId" AND fsu.permission::text = 'submission_create'::text | ||
LEFT JOIN "user" u ON fsu."userId" = u.id | ||
JOIN ( | ||
SELECT form_submission_status."submissionId", form_submission_status."createdAt", ROW_NUMBER() OVER (PARTITION BY form_submission_status."submissionId" ORDER BY form_submission_status."createdAt" DESC) AS rn | ||
FROM form_submission_status where form_submission_status.code='SUBMITTED' | ||
) fss | ||
ON s."submissionId" = fss."submissionId" WHERE fss.rn = 1 | ||
ORDER BY s."createdAt", s."formName", s.version;`) | ||
); | ||
}; | ||
|
||
exports.down = function (knex) { | ||
return Promise.resolve() | ||
.then(() => knex.schema.dropViewIfExists('submissions_data_vw')) | ||
.then(() => | ||
knex.schema.raw( | ||
`CREATE OR REPLACE VIEW public.submissions_data_vw | ||
AS SELECT s."confirmationId", | ||
s."formName", | ||
s.version, | ||
s."createdAt", | ||
CASE | ||
WHEN u.id IS NULL THEN 'public'::character varying(255) | ||
ELSE u."fullName" | ||
END AS "fullName", | ||
CASE | ||
WHEN u.id IS NULL THEN 'public'::character varying(255) | ||
ELSE u.username | ||
END AS username, | ||
u.email, | ||
fs.submission -> 'data'::text AS submission, | ||
fs."updatedAt", | ||
fs."updatedBy", | ||
s.deleted, | ||
s.draft, | ||
s."submissionId", | ||
s."formId", | ||
s."formVersionId", | ||
u.id AS "userId", | ||
u."idpUserId", | ||
u."firstName", | ||
u."lastName", | ||
s."formSubmissionStatusCode" AS status, | ||
s."formSubmissionAssignedToFullName" AS assignee, | ||
s."formSubmissionAssignedToEmail" AS "assigneeEmail" | ||
FROM submissions_vw s | ||
JOIN form_submission fs ON s."submissionId" = fs.id | ||
LEFT JOIN form_submission_user fsu ON s."submissionId" = fsu."formSubmissionId" AND fsu.permission::text = 'submission_create'::text | ||
LEFT JOIN "user" u ON fsu."userId" = u.id | ||
ORDER BY s."createdAt", s."formName", s.version;` | ||
) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters