Skip to content

Commit

Permalink
Merge branch 'main' into forms-960-idp-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
usingtechnology authored Jan 26, 2024
2 parents 22a4377 + 7cb9c4e commit 48269b1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
3 changes: 3 additions & 0 deletions app/src/forms/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ module.exports = Object.freeze({
FORM_SUBMITTED: 'eventSubmission',
FORM_STATUS_CHANGE: 'eventStatusChange',
FORM_ASSIGNMENT: 'eventAssignment',
FORM_PUBLISHED: 'eventFormPublished',
FORM_DRAFT_PUBLISHED: 'eventFormDraftPublished',
FORM_UNPUBLISHED: 'eventFormUnPublished',
},
StorageTypes: {
UPLOADS: 'uploads',
Expand Down
41 changes: 34 additions & 7 deletions app/src/forms/form/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,21 @@ const service = {

await trx.commit();

const { subscribe } = await service.readForm(formId);
if (subscribe && subscribe.enabled) {
const subscribeConfig = await service.readFormSubscriptionDetails(formId);
const config = Object.assign({}, subscribe, subscribeConfig);
const formVersion = new FormVersion();
formVersion.id = formVersionId;
formVersion.formId = formId;

if (publish) {
service.postSubscriptionEvent(config, formVersion, null, SubscriptionEvent.FORM_PUBLISHED);
} else {
service.postSubscriptionEvent(config, formVersion, null, SubscriptionEvent.FORM_UNPUBLISHED);
}
}

// return the published form/version...
return await service.readPublishedForm(formId);
} catch (err) {
Expand Down Expand Up @@ -483,11 +498,11 @@ const service = {
};

await FormSubmissionStatus.query(trx).insert(stObj);
}
if (subscribe && subscribe.enabled) {
const subscribeConfig = await service.readFormSubscriptionDetails(formVersion.formId);
const config = Object.assign({}, subscribe, subscribeConfig);
service.postSubscriptionEvent(config, formVersion, submissionId, SubscriptionEvent.FORM_SUBMITTED);
if (subscribe && subscribe.enabled) {
const subscribeConfig = await service.readFormSubscriptionDetails(formVersion.formId);
const config = Object.assign({}, subscribe, subscribeConfig);
service.postSubscriptionEvent(config, formVersion, submissionId, SubscriptionEvent.FORM_SUBMITTED);
}
}

// does this submission contain any file uploads?
Expand Down Expand Up @@ -670,6 +685,16 @@ const service = {
await FormVersionDraft.query().deleteById(formVersionDraftId);
await trx.commit();

const { subscribe } = await service.readForm(formId);
if (subscribe && subscribe.enabled) {
const subscribeConfig = await service.readFormSubscriptionDetails(formId);
const config = Object.assign({}, subscribe, subscribeConfig);
const formVersion = new FormVersion();
formVersion.id = version.id;
formVersion.formId = formId;
service.postSubscriptionEvent(config, formVersion, null, SubscriptionEvent.FORM_DRAFT_PUBLISHED);
}

// return the published version...
return await service.readVersion(version.id);
} catch (err) {
Expand Down Expand Up @@ -748,7 +773,10 @@ const service = {
if (subscribe && subscribe.endpointUrl) {
const axiosOptions = { timeout: 10000 };
const axiosInstance = axios.create(axiosOptions);
const jsonData = { formId: formVersion.formId, formVersion: formVersion.id, submissionId: submissionId, subscriptionEvent: subscriptionEvent };
const jsonData = { formId: formVersion.formId, formVersion: formVersion.id, subscriptionEvent: subscriptionEvent };
if (submissionId != null) {
jsonData['submissionId'] = submissionId;
}

axiosInstance.interceptors.request.use(
(cfg) => {
Expand All @@ -759,7 +787,6 @@ const service = {
return Promise.reject(error);
}
);

axiosInstance.post(subscribe.endpointUrl, jsonData);
}
} catch (err) {
Expand Down

0 comments on commit 48269b1

Please sign in to comment.