Skip to content

Commit

Permalink
adds Lab PI field to labs content type and deletes Lab Membership con…
Browse files Browse the repository at this point in the history
…tent model
  • Loading branch information
AimeurAmin committed Jan 27, 2025
1 parent 961ae1f commit 7c8b59b
Showing 1 changed file with 133 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
module.exports.description =
'adds Lab PI field to labs content type and removes Lab Membership content model';

module.exports.up = (migration) => {
const labs = migration.editContentType('labs');

labs
.createField('labPI')
.name('Lab PI')
.type('Link')
.localized(false)
.required(false)
.disabled(false)
.omitted(false)
.validations([
{
linkContentType: ['users'],
},
])
.linkType('Entry');

const users = migration.editContentType('users');
users
.editField('labs')
.name('Labs')
.type('Array')
.localized(false)
.required(false)
.validations([])
.disabled(false)
.omitted(false)
.items({
type: 'Link',
validations: [
{
linkContentType: ['labs'],
},
],
linkType: 'Entry',
});

migration.transformEntries({
contentType: 'users',
from: ['labs'],
to: ['labs'],
transformEntryForLocale: (entry, locale) => {
if (!entry.fields.labs || !entry.fields.labs[locale]) {
return;
}

const updatedLabs = entry.fields.labs[locale]
.map((membership) => {
if (!membership.sys || !membership.sys.id) {
return null;
}
return {
sys: {
type: 'Link',
linkType: 'Entry',
id: membership.sys.id,
},
};
})
.filter(Boolean);

return {
labs: updatedLabs,
};
},
});

migration.transformEntries({
contentType: 'labs',
from: ['labPI'],
to: ['labPI'],
transformEntryForLocale: (entry, locale) => {
if (!entry.fields.labPI || !entry.fields.labPI[locale]) {
return;
}
return {
labPI: entry.fields.labPI[locale],
};
},
});

migration.deleteContentType('labMembership');
};

module.exports.down = (migration) => {
const labs = migration.editContentType('labs');
labs.deleteField('labPI');

const labMembership = migration
.createContentType('labMembership')
.name('Lab Membership')
.description('Contains details about lab memberships')
.displayField('lab');

labMembership
.createField('lab')
.name('Lab')
.type('Link')
.localized(false)
.required(true)
.validations([{ linkContentType: ['labs'] }])
.linkType('Entry');

labMembership
.createField('role')
.name('Role')
.type('Symbol')
.validations([{ in: ['Co-PI', 'Lead PI', 'Collaborating PI'] }]);

const users = migration.editContentType('users');
users
.editField('labs')
.name('Labs')
.type('Array')
.localized(false)
.required(false)
.validations([])
.disabled(false)
.omitted(false)
.items({
type: 'Link',
validations: [
{
linkContentType: ['labMembership'],
},
],
linkType: 'Entry',
});
};

0 comments on commit 7c8b59b

Please sign in to comment.