Skip to content

Commit 604402c

Browse files
authored
Merge pull request #2288 from uditijmehta/feature/mirage-preprints
[ENG-6015] Add User Preprint List Endpoint to Mirage Server
2 parents 36b7cce + c53415f commit 604402c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

mirage/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
claimUnregisteredUser,
4747
userNodeList,
4848
userRegistrationList,
49+
userPreprintList,
4950
} from './views/user';
5051
import { updatePassword } from './views/user-password';
5152
import * as userSettings from './views/user-setting';
@@ -312,6 +313,7 @@ export default function(this: Server) {
312313
this.get('/users/:id/nodes', userNodeList);
313314
this.get('/sparse/users/:id/nodes', userNodeList);
314315
this.get('/users/:id/registrations', userRegistrationList);
316+
this.get('/users/:id/preprints', userPreprintList);
315317
osfNestedResource(this, 'user', 'draftRegistrations', {
316318
only: ['index'],
317319
});

mirage/views/user.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ export function userRegistrationList(this: HandlerContext, schema: Schema, reque
3030
return json;
3131
}
3232

33+
export function userPreprintList(this: HandlerContext, schema: Schema, request: Request) {
34+
const user = schema.users.find(request.params.id);
35+
const preprints = [];
36+
const { contributorIds } = user;
37+
38+
for (const contributorId of contributorIds as string[]) {
39+
const contributor = schema.contributors.find(contributorId);
40+
const preprint = contributor.preprint;
41+
if (preprint && filter(preprint, request)) {
42+
preprints.push(this.serialize(preprint).data);
43+
}
44+
}
45+
46+
const json = process(schema, request, this, preprints, { defaultSortKey: 'last_logged' });
47+
return json;
48+
}
49+
3350
export function claimUnregisteredUser(this: HandlerContext) {
3451
return new Response(204);
3552
}

0 commit comments

Comments
 (0)