Skip to content

Commit

Permalink
[ASAP-534] - update quick check details fields (#4420)
Browse files Browse the repository at this point in the history
* update quick check details

* update queries & data provider

* fix data provider test update

* add missing tests

* update test to pass copy paste check

* Apply suggestions from code review

Co-authored-by: Gabriela Ueno <[email protected]>

* remove unnecessary function

---------

Co-authored-by: Gabriela Ueno <[email protected]>
  • Loading branch information
AkosuaA and gabiayako authored Oct 24, 2024
1 parent 8d26292 commit 618b01d
Show file tree
Hide file tree
Showing 13 changed files with 1,014 additions and 662 deletions.
3 changes: 2 additions & 1 deletion .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getLinkEntities,
getLinkEntity,
GraphQLClient,
Link,
} from '@asap-hub/contentful';
import {
ListResponse,
Expand All @@ -22,6 +23,8 @@ import {
ManuscriptType,
manuscriptTypes,
ManuscriptVersion,
QuickCheckDetails,
QuickCheckDetailsObject,
} from '@asap-hub/model';
import { parseUserDisplayName } from '@asap-hub/server-common';

Expand Down Expand Up @@ -105,6 +108,23 @@ export class ManuscriptContentfulDataProvider
await additionalFileAsset.publish();
});

const quickCheckDetails = {
asapAffiliationIncludedDetails: version.asapAffiliationIncludedDetails,
acknowledgedGrantNumberDetails: version.acknowledgedGrantNumberDetails,
availabilityStatementDetails: version.availabilityStatementDetails,
codeDepositedDetails: version.codeDepositedDetails,
datasetsDepositedDetails: version.datasetsDepositedDetails,
labMaterialsRegisteredDetails: version.labMaterialsRegisteredDetails,
manuscriptLicenseDetails: version.manuscriptLicenseDetails,
protocolsDepositedDetails: version.protocolsDepositedDetails,
};

const quickCheckDiscussions = await createQuickCheckDiscussions(
environment,
quickCheckDetails,
userId,
);

const manuscriptVersionEntry = await environment.createEntry(
'manuscriptVersions',
{
Expand All @@ -128,6 +148,7 @@ export class ManuscriptContentfulDataProvider
)
: null,
createdBy: getLinkEntity(userId),
...quickCheckDiscussions,
}),
},
);
Expand Down Expand Up @@ -204,35 +225,35 @@ export const parseGraphqlManuscriptVersion = (
otherDetails: version?.otherDetails,
acknowledgedGrantNumberDetails:
version?.acknowledgedGrantNumber === 'No'
? version?.acknowledgedGrantNumberDetails
? version?.acknowledgedGrantNumberDetails?.message?.text
: undefined,
asapAffiliationIncludedDetails:
version?.asapAffiliationIncluded === 'No'
? version?.asapAffiliationIncludedDetails
? version?.asapAffiliationIncludedDetails?.message?.text
: undefined,
manuscriptLicenseDetails:
version?.manuscriptLicense === 'No'
? version?.manuscriptLicenseDetails
? version?.manuscriptLicenseDetails?.message?.text
: undefined,
datasetsDepositedDetails:
version?.datasetsDeposited === 'No'
? version?.datasetsDepositedDetails
? version?.datasetsDepositedDetails?.message?.text
: undefined,
codeDepositedDetails:
version?.codeDeposited === 'No'
? version?.codeDepositedDetails
? version?.codeDepositedDetails?.message?.text
: undefined,
protocolsDepositedDetails:
version?.protocolsDeposited === 'No'
? version?.protocolsDepositedDetails
? version?.protocolsDepositedDetails?.message?.text
: undefined,
labMaterialsRegisteredDetails:
version?.labMaterialsRegistered === 'No'
? version?.labMaterialsRegisteredDetails
? version?.labMaterialsRegisteredDetails?.message?.text
: undefined,
availabilityStatementDetails:
version?.availabilityStatement === 'No'
? version?.availabilityStatementDetails
? version?.availabilityStatementDetails?.message?.text
: undefined,
createdBy: {
id: version?.createdBy?.sys.id,
Expand Down Expand Up @@ -285,3 +306,46 @@ const parseComplianceReport = (
url: complianceReport.url,
description: complianceReport.description,
};

const createQuickCheckDiscussions = async (
environment: Environment,
quickCheckDetails: QuickCheckDetailsObject,
userId: string,
) => {
const generatedDiscussions = {} as Record<
QuickCheckDetails,
Link<'Entry'> | null
>;
await Promise.all(
Object.entries(quickCheckDetails).map(
async ([quickCheckDetail, fieldValue]) => {
if (fieldValue) {
const user = getLinkEntity(userId);
const messageEntry = await environment.createEntry('messages', {
fields: addLocaleToFields({
text: fieldValue,
createdBy: user,
}),
});

await messageEntry.publish();

const messageId = messageEntry.sys.id;
const discussionEntry = await environment.createEntry('discussions', {
fields: addLocaleToFields({
message: getLinkEntity(messageId),
}),
});

await discussionEntry.publish();

generatedDiscussions[quickCheckDetail as QuickCheckDetails] =
getLinkEntity(discussionEntry.sys.id);
} else {
generatedDiscussions[quickCheckDetail as QuickCheckDetails] = null;
}
},
),
);
return generatedDiscussions;
};
Loading

0 comments on commit 618b01d

Please sign in to comment.