forked from DebaucheryLibrarian/traxxx
91 lines
2.9 KiB
JavaScript
91 lines
2.9 KiB
JavaScript
'use strict';
|
|
|
|
const { makeExtendSchemaPlugin, gql } = require('graphile-utils');
|
|
const moment = require('moment');
|
|
const { cmToFeetInches, cmToInches, kgToLbs } = require('../../utils/convert');
|
|
|
|
const schemaExtender = makeExtendSchemaPlugin(_build => ({
|
|
typeDefs: gql`
|
|
enum Units {
|
|
METRIC
|
|
IMPERIAL
|
|
}
|
|
|
|
extend type Actor {
|
|
isFavorited: Boolean @requires(columns: ["stashesActors"])
|
|
isStashed(includeFavorites: Boolean = false): Boolean @requires(columns: ["stashesActors"])
|
|
ageFromBirth: Int @requires(columns: ["dateOfBirth"])
|
|
ageAtDeath: Int @requires(columns: ["dateOfBirth", "dateOfDeath"])
|
|
height(units: Units): String @requires(columns: ["height"])
|
|
weight(units: Units): String @requires(columns: ["weight"])
|
|
penisLength(units: Units): String @requires(columns: ["penis_length"])
|
|
penisGirth(units: Units): String @requires(columns: ["penis_girth"])
|
|
}
|
|
`,
|
|
resolvers: {
|
|
Actor: {
|
|
isFavorited(parent) {
|
|
if (!parent['@stashes'] || (parent['@stashes'].length > 0 && typeof parent['@stashes'][0]['@stash'].primary === 'undefined')) {
|
|
return null;
|
|
}
|
|
|
|
return parent['@stashes'].some(({ '@stash': stash }) => stash.primary);
|
|
},
|
|
isStashed(parent, args) {
|
|
if (!parent['@stashes'] || (parent['@stashes'].length > 0 && typeof parent['@stashes'][0]['@stash'].primary === 'undefined')) {
|
|
return null;
|
|
}
|
|
|
|
if (args.includeFavorites) {
|
|
return parent['@stashes'].length > 0;
|
|
}
|
|
|
|
return parent['@stashes'].some(({ '@stash': stash }) => !stash.primary);
|
|
},
|
|
ageFromBirth(parent, _args, _context, _info) {
|
|
if (!parent.dateOfBirth) return null;
|
|
|
|
return moment().diff(parent.dateOfBirth, 'years');
|
|
},
|
|
ageAtDeath(parent, _args, _context, _info) {
|
|
if (!parent.dateOfDeath) return null;
|
|
|
|
return moment(parent.dateOfDeath).diff(parent.dateOfBirth, 'years');
|
|
},
|
|
height(parent, args, _context, _info) {
|
|
if (!parent.height) return null;
|
|
|
|
if (args.units === 'IMPERIAL') {
|
|
const { feet, inches } = cmToFeetInches(parent.height);
|
|
return `${feet}' ${inches}"`;
|
|
}
|
|
|
|
return parent.height.toString();
|
|
},
|
|
weight(parent, args, _context, _info) {
|
|
if (!parent.weight) return null;
|
|
|
|
return args.units === 'IMPERIAL'
|
|
? kgToLbs(parent.weight).toString()
|
|
: parent.weight.toString();
|
|
},
|
|
penisLength(parent, args, _context, _info) {
|
|
if (!parent.penisLength) return null;
|
|
|
|
return args.units === 'IMPERIAL'
|
|
? (Math.round(cmToInches(parent.penisLength) * 4) / 4).toString() // round to nearest quarter inch
|
|
: parent.penisLength.toString();
|
|
},
|
|
penisGirth(parent, args, _context, _info) {
|
|
if (!parent.penisGirth) return null;
|
|
|
|
return args.units === 'IMPERIAL'
|
|
? (Math.round(cmToInches(parent.penisGirth) * 4) / 4).toString() // round to nearest quarter inch
|
|
: parent.penisGirth.toString();
|
|
},
|
|
},
|
|
},
|
|
}));
|
|
|
|
module.exports = [schemaExtender];
|