Added actor creation page.
This commit is contained in:
@@ -3,6 +3,7 @@ import { differenceInYears } from 'date-fns';
|
||||
import { unit } from 'mathjs';
|
||||
import { MerkleJson } from 'merkle-json';
|
||||
import moment from 'moment';
|
||||
import { nanoid } from 'nanoid';
|
||||
import omit from 'object.omit';
|
||||
import convert from 'convert';
|
||||
import unprint from 'unprint';
|
||||
@@ -521,6 +522,27 @@ export async function fetchActors(filters, rawOptions, reqUser) {
|
||||
};
|
||||
}
|
||||
|
||||
function curateActorEntry(actor, context) {
|
||||
return {
|
||||
name: actor.name,
|
||||
slug: slugify(actor.name),
|
||||
entry_id: nanoid(), // allows for manual creation of multiple actors with the same name
|
||||
gender: actor.gender,
|
||||
comment: context?.comment,
|
||||
};
|
||||
}
|
||||
|
||||
export async function createActor(newActor, context, reqUser) {
|
||||
if (!reqUser || reqUser.role === 'user') {
|
||||
throw new HttpError('You are not permitted to create actors', 403);
|
||||
}
|
||||
|
||||
const curatedActorEntry = curateActorEntry(newActor, context);
|
||||
const [actorEntry] = await knex('actors').insert(curatedActorEntry).returning('*');
|
||||
|
||||
return curateActor(actorEntry);
|
||||
}
|
||||
|
||||
export async function fetchActorRevisions(revisionId, filters = {}, reqUser) {
|
||||
const limit = filters.limit || 50;
|
||||
const page = filters.page || 1;
|
||||
|
||||
Reference in New Issue
Block a user