Added database structure for profiles and tattoos. Improved sidebar appearance. Expanded new actors module.
This commit is contained in:
@@ -1,28 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
const knex = require('./knex');
|
||||
const slugify = require('./utils/slugify');
|
||||
const capitalize = require('./utils/capitalize');
|
||||
|
||||
function toBaseActors(actorsOrNames) {
|
||||
function toBaseActors(actorsOrNames, release) {
|
||||
return actorsOrNames.map((actorOrName) => {
|
||||
if (actorOrName.name) {
|
||||
return {
|
||||
...actorOrName,
|
||||
name: capitalize(actorOrName.name),
|
||||
slug: slugify(actorOrName.name),
|
||||
networkId: release.site.network.id,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
name: actorOrName,
|
||||
slug: slugify(actorOrName.name),
|
||||
name: capitalize(actorOrName),
|
||||
slug: slugify(actorOrName),
|
||||
networkId: release.site.network.id,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function associateActors(releases) {
|
||||
const rawActors = releases.map(release => release.actors).flat().filter(Boolean);
|
||||
const baseActors = toBaseActors(rawActors);
|
||||
function curateActorEntry(baseActor) {
|
||||
const actorEntry = {
|
||||
name: baseActor.name,
|
||||
slug: baseActor.slug,
|
||||
};
|
||||
|
||||
console.log(baseActors);
|
||||
if (baseActor.name.split(/\s+/).length === 1) {
|
||||
// attach network ID for single names, to reduce mismatches
|
||||
actorEntry.network_id = baseActor.networkId;
|
||||
}
|
||||
|
||||
return actorEntry;
|
||||
}
|
||||
|
||||
function curateActorEntries(baseActors) {
|
||||
return baseActors.map(baseActor => curateActorEntry(baseActor));
|
||||
}
|
||||
|
||||
async function getActors(baseActors) {
|
||||
const existingActors = await knex('actors')
|
||||
.whereIn('slug', baseActors.map(baseActor => baseActor.slug))
|
||||
.orWhereIn('name', baseActors.map(baseActor => baseActor.slug));
|
||||
|
||||
if (existingActors.length === 0) {
|
||||
// TODO: TESTING ONLY
|
||||
await knex('actors').insert(curateActorEntries(baseActors.slice(0, 3)));
|
||||
}
|
||||
|
||||
console.log(existingActors);
|
||||
}
|
||||
|
||||
async function associateActors(releases) {
|
||||
const baseActorsByReleaseId = releases.reduce((acc, release) => {
|
||||
if (release.actors) {
|
||||
acc[release.id] = toBaseActors(release.actors, release);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const baseActors = Object.values(baseActorsByReleaseId).flat();
|
||||
const baseActorsBySlug = baseActors.reduce((acc, baseActor) => ({ ...acc, [baseActor.slug]: baseActor }), {});
|
||||
const uniqueBaseActors = Object.values(baseActorsBySlug);
|
||||
|
||||
const actors = await getActors(uniqueBaseActors);
|
||||
|
||||
console.log(actors);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -6,7 +6,7 @@ function capitalize(string, trim = true) {
|
||||
}
|
||||
|
||||
const capitalized = string
|
||||
.split(/\s/)
|
||||
.split(/\s+/)
|
||||
.map(component => `${component.charAt(0).toUpperCase()}${component.slice(1)}`)
|
||||
.join(' ');
|
||||
|
||||
|
||||
@@ -11,14 +11,14 @@ const schemaExtender = makeExtendSchemaPlugin(_build => ({
|
||||
IMPERIAL
|
||||
}
|
||||
|
||||
extend type Actor {
|
||||
extend type ActorProfile {
|
||||
age: Int @requires(columns: ["birthdate"])
|
||||
height(units:Units): String @requires(columns: ["height"])
|
||||
weight(units:Units): String @requires(columns: ["weight"])
|
||||
}
|
||||
`,
|
||||
resolvers: {
|
||||
Actor: {
|
||||
ActorProfile: {
|
||||
age(parent, _args, _context, _info) {
|
||||
if (!parent.birthdate) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user