Skip to content

Commit

Permalink
Add identifier relationship to preprint (CenterForOpenScience#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda authored and bp-cos committed Jan 31, 2024
1 parent 7e8697a commit de71704
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/models/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { attr, belongsTo, AsyncBelongsTo } from '@ember-data/model';

import NodeModel from './node';
import OsfModel from './osf-model';
import PreprintModel from './preprint';

export default class IdentifierModel extends OsfModel {
@attr('fixstring') category!: string;
@attr('fixstring') value!: string;

@belongsTo('node', { inverse: 'identifiers', polymorphic: true })
referent!: AsyncBelongsTo<NodeModel> & NodeModel;
referent!: AsyncBelongsTo<NodeModel | PreprintModel> & (NodeModel | PreprintModel);
}

declare module 'ember-data/types/registries/model' {
Expand Down
4 changes: 4 additions & 0 deletions app/models/preprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ReviewActionModel from 'ember-osf-web/models/review-action';

import ContributorModel from './contributor';
import FileModel from './file';
import IdentifierModel from './identifier';
import LicenseModel from './license';
import NodeModel from './node';
import OsfModel, { Permission } from './osf-model';
Expand Down Expand Up @@ -89,6 +90,9 @@ export default class PreprintModel extends OsfModel {
@hasMany('preprint-request', { inverse: 'target'})
requests!: AsyncHasMany<PreprintRequestModel>;

@hasMany('identifiers', { inverse: 'referent' })
identifiers!: AsyncHasMany<IdentifierModel>;

@alias('links.doi') articleDoiUrl!: string | null;
@alias('links.preprint_doi') preprintDoiUrl!: string;

Expand Down
5 changes: 5 additions & 0 deletions mirage/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ export default function(this: Server) {
defaultSortKey: 'index',
relatedModelName: 'subject',
});
osfNestedResource(this, 'preprint', 'identifiers', {
path: '/preprints/:parentID/identifiers/',
defaultSortKey: 'index',
relatedModelName: 'identifier',
});
this.get('/preprints/:guid/citation/:citationStyleID', getCitation);

/**
Expand Down
3 changes: 1 addition & 2 deletions mirage/factories/identifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { belongsTo, Factory } from 'ember-cli-mirage';
import { Factory } from 'ember-cli-mirage';
import faker from 'faker';

import Identifier from 'ember-osf-web/models/identifier';
Expand All @@ -8,7 +8,6 @@ export default Factory.extend<Identifier>({
value() {
return faker.fake('10.5555/{{company.bsNoun}}');
},
referent: belongsTo({ polymorphic: true }),
});

declare module 'ember-cli-mirage/types/registries/schema' {
Expand Down
4 changes: 4 additions & 0 deletions mirage/scenarios/preprints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function buildOSF(
hasPreregLinks: PreprintPreregLinksEnum.NOT_APPLICABLE,
});

const osfApprovedAdminIdentifier = server.create('identifier');

approvedAdminPreprint.update({ identifiers: [osfApprovedAdminIdentifier] });

const notContributorPreprint = server.create('preprint', {
provider: osf,
id: 'osf-not-contributor',
Expand Down
8 changes: 8 additions & 0 deletions mirage/serializers/preprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ export default class PreprintSerializer extends ApplicationSerializer<PreprintMi
},
},
},
identifiers: {
links: {
related: {
href: `${apiUrl}/v2/preprints/${model.id}/identifiers/`,
meta: this.buildRelatedLinkMeta(model, 'identifiers'),
},
},
},
};

if (model.license !== null) {
Expand Down

0 comments on commit de71704

Please sign in to comment.