Skip to content

Commit

Permalink
refactor(models): Move all current modesl under 2014 folder
Browse files Browse the repository at this point in the history
  • Loading branch information
bagelbits committed Dec 25, 2024
1 parent aafe8c7 commit 481b0ee
Show file tree
Hide file tree
Showing 144 changed files with 367 additions and 414 deletions.
2 changes: 1 addition & 1 deletion src/controllers/api/abilityScoreController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AbilityScore from '../../models/abilityScore/index.js';
import AbilityScore from '../../models/2014/abilityScore/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(AbilityScore);
2 changes: 1 addition & 1 deletion src/controllers/api/alignmentController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Alignment from '../../models/alignment/index.js';
import Alignment from '../../models/2014/alignment/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(Alignment);
2 changes: 1 addition & 1 deletion src/controllers/api/backgroundController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Background from '../../models/background/index.js';
import Background from '../../models/2014/background/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(Background);
12 changes: 6 additions & 6 deletions src/controllers/api/classController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Request, Response, NextFunction } from 'express';

import { ResourceList, escapeRegExp } from '../../util/index.js';

import Class from '../../models/class/index.js';
import Feature from '../../models/feature/index.js';
import Level from '../../models/level/index.js';
import Proficiency from '../../models/proficiency/index.js';
import Class from '../../models/2014/class/index.js';
import Feature from '../../models/2014/feature/index.js';
import Level from '../../models/2014/level/index.js';
import Proficiency from '../../models/2014/proficiency/index.js';
import SimpleController from '../simpleController.js';
import Spell from '../../models/spell/index.js';
import Subclass from '../../models/subclass/index.js';
import Spell from '../../models/2014/spell/index.js';
import Subclass from '../../models/2014/subclass/index.js';

const simpleController = new SimpleController(Class);
interface ShowLevelsForClassQuery {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/api/conditionController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Condition from '../../models/condition/index.js';
import Condition from '../../models/2014/condition/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(Condition);
2 changes: 1 addition & 1 deletion src/controllers/api/damageTypeController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DamageType from '../../models/damageType/index.js';
import DamageType from '../../models/2014/damageType/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(DamageType);
2 changes: 1 addition & 1 deletion src/controllers/api/equipmentCategoryController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EquipmentCategory from '../../models/equipmentCategory/index.js';
import EquipmentCategory from '../../models/2014/equipmentCategory/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(EquipmentCategory);
2 changes: 1 addition & 1 deletion src/controllers/api/equipmentController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Equipment from '../../models/equipment/index.js';
import Equipment from '../../models/2014/equipment/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(Equipment);
2 changes: 1 addition & 1 deletion src/controllers/api/featController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Feat from '../../models/feat/index.js';
import Feat from '../../models/2014/feat/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(Feat);
2 changes: 1 addition & 1 deletion src/controllers/api/featureController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Feature from '../../models/feature/index.js';
import Feature from '../../models/2014/feature/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(Feature);
2 changes: 1 addition & 1 deletion src/controllers/api/languageController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Language from '../../models/language/index.js';
import Language from '../../models/2014/language/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(Language);
2 changes: 1 addition & 1 deletion src/controllers/api/magicItemController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from 'express';

import { ResourceList, escapeRegExp, redisClient } from '../../util/index.js';
import MagicItem from '../../models/magicItem/index.js';
import MagicItem from '../../models/2014/magicItem/index.js';

interface IndexQuery {
name?: { $regex: RegExp };
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/api/magicSchoolController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MagicSchool from '../../models/magicSchool/index.js';
import MagicSchool from '../../models/2014/magicSchool/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(MagicSchool);
4 changes: 2 additions & 2 deletions src/controllers/api/monsterController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Request, Response, NextFunction } from 'express';

import { ResourceList, escapeRegExp, redisClient } from '../../util/index.js';

import Monster from '../../models/monster/index.js';
import Monster from '../../models/2014/monster/index.js';

interface IndexQuery {
name?: { $regex: RegExp };
Expand All @@ -22,7 +22,7 @@ export const index = async (req: Request, res: Response, next: NextFunction) =>

const challengeRating = req.query.challenge_rating as string[];
searchQueries.challenge_rating = {
$in: challengeRating.map(Number).filter(item => !isNaN(item)),
$in: challengeRating.map(Number).filter((item) => !isNaN(item)),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/api/proficiencyController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Proficiency from '../../models/proficiency/index.js';
import Proficiency from '../../models/2014/proficiency/index.js';
import SimpleController from '../simpleController.js';

export default new SimpleController(Proficiency);
8 changes: 4 additions & 4 deletions src/controllers/api/raceController.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Request, Response, NextFunction } from 'express';

import Proficiency from '../../models/proficiency/index.js';
import Race from '../../models/race/index.js';
import Proficiency from '../../models/2014/proficiency/index.js';
import Race from '../../models/2014/race/index.js';
import { ResourceList } from '../../util/data.js';
import SimpleController from '../simpleController.js';
import Subrace from '../../models/subrace/index.js';
import Trait from '../../models/trait/index.js';
import Subrace from '../../models/2014/subrace/index.js';
import Trait from '../../models/2014/trait/index.js';

const simpleController = new SimpleController(Race);

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/api/ruleController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from 'express';
import { ResourceList, escapeRegExp, redisClient } from '../../util/index.js';

import Rule from '../../models/rule/index.js';
import Rule from '../../models/2014/rule/index.js';

interface IndexQuery {
name?: { $regex: RegExp };
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/api/ruleSectionController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from 'express';
import { ResourceList, escapeRegExp, redisClient } from '../../util/index.js';

import RuleSection from '../../models/ruleSection/index.js';
import RuleSection from '../../models/2014/ruleSection/index.js';
interface IndexQuery {
name?: { $regex: RegExp };
desc?: { $regex: RegExp };
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/api/skillController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SimpleController from '../simpleController.js';
import Skill from '../../models/skill/index.js';
import Skill from '../../models/2014/skill/index.js';

export default new SimpleController(Skill);
4 changes: 2 additions & 2 deletions src/controllers/api/spellController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface IndexQuery {
'school.name'?: { $in: RegExp[] };
}

import Spell from '../../models/spell/index.js';
import Spell from '../../models/2014/spell/index.js';

export const index = async (req: Request, res: Response, next: NextFunction) => {
try {
Expand All @@ -23,7 +23,7 @@ export const index = async (req: Request, res: Response, next: NextFunction) =>
if (req.query.school !== undefined) {
let schoolRegex;
if (Array.isArray(req.query.school)) {
schoolRegex = req.query.school.map(c => new RegExp(escapeRegExp(c as string), 'i'));
schoolRegex = req.query.school.map((c) => new RegExp(escapeRegExp(c as string), 'i'));
} else {
schoolRegex = [new RegExp(escapeRegExp(req.query.school as string), 'i')];
}
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/api/subclassController.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Request, Response, NextFunction } from 'express';
import Feature from '../../models/feature/index.js';
import Level from '../../models/level/index.js';
import Feature from '../../models/2014/feature/index.js';
import Level from '../../models/2014/level/index.js';
import { ResourceList } from '../../util/data.js';
import SimpleController from '../simpleController.js';
import Subclass from '../../models/subclass/index.js';
import Subclass from '../../models/2014/subclass/index.js';

const simpleController = new SimpleController(Subclass);

Expand Down
6 changes: 3 additions & 3 deletions src/controllers/api/subraceController.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Request, Response, NextFunction } from 'express';
import Proficiency from '../../models/proficiency/index.js';
import Proficiency from '../../models/2014/proficiency/index.js';
import { ResourceList } from '../../util/data.js';
import SimpleController from '../simpleController.js';
import Subrace from '../../models/subrace/index.js';
import Trait from '../../models/trait/index.js';
import Subrace from '../../models/2014/subrace/index.js';
import Trait from '../../models/2014/trait/index.js';

const simpleController = new SimpleController(Subrace);

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/api/traitController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SimpleController from '../simpleController.js';
import Trait from '../../models/trait/index.js';
import Trait from '../../models/2014/trait/index.js';

export default new SimpleController(Trait);
2 changes: 1 addition & 1 deletion src/controllers/api/weaponPropertyController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SimpleController from '../simpleController.js';
import WeaponProperty from '../../models/weaponProperty/index.js';
import WeaponProperty from '../../models/2014/weaponProperty/index.js';

export default new SimpleController(WeaponProperty);
4 changes: 2 additions & 2 deletions src/controllers/apiController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Response, NextFunction } from 'express';
import Collection from '../models/collection/index.js';
import Collection from '../models/2014/collection/index.js';

export const index = async (req: Request, res: Response, next: NextFunction) => {
try {
Expand All @@ -9,7 +9,7 @@ export const index = async (req: Request, res: Response, next: NextFunction) =>
.exec();

const apiIndex: Record<string, string> = {};
data.forEach(item => {
data.forEach((item) => {
if (item.index === 'levels') return;

apiIndex[item.index] = `/api/${item.index}`;
Expand Down
10 changes: 4 additions & 6 deletions src/graphql/resolvers/abilityScoreResolver.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import SkillModel from '../../models/skill/index.js';
import SkillModel from '../../models/2014/skill/index.js';
import {
coalesceFilters,
getMongoSortDirection,
resolveContainsStringFilter,
SortQuery,
QueryParams,
} from './common.js';
import { AbilityScore } from '../../models/abilityScore/types';
import { AbilityScore } from '../../models/2014/abilityScore/types.js';

const AbilityScoreResolver = {
skills: async (abilityScore: AbilityScore, args: QueryParams) => {
const filters: any[] = [{ index: { $in: abilityScore.skills.map(s => s.index) } }];
const filters: any[] = [{ index: { $in: abilityScore.skills.map((s) => s.index) } }];

if (args.name) {
filters.push(resolveContainsStringFilter(args.name));
Expand All @@ -21,9 +21,7 @@ const AbilityScoreResolver = {
sort.name = getMongoSortDirection(args.order_direction);
}

return await SkillModel.find(coalesceFilters(filters))
.sort(sort)
.lean();
return await SkillModel.find(coalesceFilters(filters)).sort(sort).lean();
},
};

Expand Down
4 changes: 2 additions & 2 deletions src/graphql/resolvers/armorResolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import EquipmentCategoryModel from '../../models/equipmentCategory/index.js';
import { Equipment } from '../../models/equipment/types';
import EquipmentCategoryModel from '../../models/2014/equipmentCategory/index.js';
import { Equipment } from '../../models/2014/equipment/types.js';
import { equipmentFieldResolvers } from './common.js';

const Armor = {
Expand Down
28 changes: 14 additions & 14 deletions src/graphql/resolvers/backgroundResolver.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import AlignmentModel from '../../models/alignment/index.js';
import EquipmentCategoryModel from '../../models/equipmentCategory/index.js';
import EquipmentModel from '../../models/equipment/index.js';
import LanguageModel from '../../models/language/index.js';
import ProficiencyModel from '../../models/proficiency/index.js';
import AlignmentModel from '../../models/2014/alignment/index.js';
import EquipmentCategoryModel from '../../models/2014/equipmentCategory/index.js';
import EquipmentModel from '../../models/2014/equipment/index.js';
import LanguageModel from '../../models/2014/language/index.js';
import ProficiencyModel from '../../models/2014/proficiency/index.js';
import {
coalesceFilters,
resolveChoice,
resolveContainsStringFilter,
QueryParams,
} from './common.js';

import { Background } from '../../models/background/types';
import { Background } from '../../models/2014/background/types.js';

const Background = {
starting_equipment: async (background: Background, args: QueryParams) => {
const starting_equipment = background.starting_equipment;
const filters: any[] = [
{
index: { $in: starting_equipment.map(se => se.equipment.index) },
index: { $in: starting_equipment.map((se) => se.equipment.index) },
},
];

Expand All @@ -27,15 +27,15 @@ const Background = {

const equipment = await EquipmentModel.find(coalesceFilters(filters)).lean();

return starting_equipment.map(se => ({
return starting_equipment.map((se) => ({
...se,
equipment: equipment.find(e => e.index === se.equipment.index),
equipment: equipment.find((e) => e.index === se.equipment.index),
}));
},
starting_proficiencies: async (background: Background, args: QueryParams) => {
const filters: any[] = [
{
index: { $in: background.starting_proficiencies.map(sp => sp.index) },
index: { $in: background.starting_proficiencies.map((sp) => sp.index) },
},
];

Expand All @@ -50,15 +50,15 @@ const Background = {
background.language_options,
{
option_set_type: 'options_array',
options: (await LanguageModel.find().lean()).map(language => ({
options: (await LanguageModel.find().lean()).map((language) => ({
option_type: 'reference',
item: language,
})),
},
true
),
starting_equipment_options: async (background: Background) =>
background.starting_equipment_options.map(async option => {
background.starting_equipment_options.map(async (option) => {
if ('equipment_category' in option.from) {
return resolveChoice(option, {
equipment_category: await EquipmentCategoryModel.findOne({
Expand All @@ -69,12 +69,12 @@ const Background = {
}),
ideals: async (background: Background) => {
if ('options' in background.ideals.from) {
const options = background.ideals.from.options.map(async option => {
const options = background.ideals.from.options.map(async (option) => {
if ('alignments' in option) {
return {
...option,
alignments: await AlignmentModel.find({
index: { $in: option.alignments.map(a => a.index) },
index: { $in: option.alignments.map((a) => a.index) },
}).lean(),
};
}
Expand Down
Loading

0 comments on commit 481b0ee

Please sign in to comment.