Skip to content

Commit

Permalink
refactor(choice structure): Choice reform and accompanying docs (#310)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Choice reform

* Update swagger docs

* Revert "Update swagger docs"

This reverts commit 242688b.

* Update swagger.yml

* Update swagger docs and make sure they actually validate

* Resolve "index Multiclassing does not exist" issue

* Update typescript types

* Update mongoose models

* Fix schema

* Update choice data in test

* Rename DC to difficulty class
  • Loading branch information
SleeplessOne1917 authored Aug 3, 2022
1 parent a69249f commit c33e2b8
Show file tree
Hide file tree
Showing 30 changed files with 4,333 additions and 4,882 deletions.
6,997 changes: 3,135 additions & 3,862 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"dependencies": {
"@apideck/portman": "^1.14.2",
"@apidevtools/swagger-cli": "^4.0.4",
"@bugsnag/js": "^7.16.1",
"@bugsnag/plugin-express": "^7.16.1",
"apollo-server-express": "^3.6.3",
Expand All @@ -42,8 +43,7 @@
"morgan": "^1.10.0",
"node-fetch": "^3.1.1",
"redis": "^4.0.4",
"serve-favicon": "^2.5.0",
"swagger-cli": "^4.0.4"
"serve-favicon": "^2.5.0"
},
"devDependencies": {
"@semantic-release/github": "^8.0.2",
Expand Down
54 changes: 7 additions & 47 deletions src/models/background/index.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,13 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const { APIReference } = require('../common');

const LanguageOptions = new Schema({
_id: false,
choose: { type: Number, index: true },
from: [APIReference],
type: { type: String, index: true },
});
const { APIReference, Choice } = require('../common');

const Equipment = new Schema({
_id: false,
equipment: APIReference,
quantity: { type: Number, index: true },
});

const StartingEquipmentOption = new Schema({
_id: false,
equipment: APIReference,
quantity: { type: Number, index: true },
});

const StartingEquipmentOptions = new Schema({
_id: false,
choose: { type: Number, index: true },
from: [StartingEquipmentOption],
type: { type: String, index: true },
});

const Ideal = new Schema({
_id: false,
desc: { type: String, index: true },
alignments: [APIReference],
});

const CharacteristicOptions = new Schema({
_id: false,
choose: { type: Number, index: true },
from: { type: [String], index: true },
type: { type: String, index: true },
});

const IdealOptions = new Schema({
_id: false,
choose: { type: Number, index: true },
from: [Ideal],
type: { type: String, index: true },
});

const Feature = new Schema({
_id: false,
name: { type: String, index: true },
Expand All @@ -59,15 +19,15 @@ const Background = new Schema({
index: { type: String, index: true },
name: { type: String, index: true },
starting_proficiencies: [APIReference],
language_options: LanguageOptions,
language_options: Choice,
url: { type: String, index: true },
starting_equipment: [Equipment],
starting_equipment_options: [StartingEquipmentOptions],
starting_equipment_options: { type: [Choice], index: true },
feature: Feature,
personality_traits: CharacteristicOptions,
ideals: IdealOptions,
bonds: CharacteristicOptions,
flaws: CharacteristicOptions,
personality_traits: Choice,
ideals: Choice,
bonds: Choice,
flaws: Choice,
});

module.exports = mongoose.model('Background', Background, 'backgrounds');
50 changes: 7 additions & 43 deletions src/models/background/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,12 @@
import * as mongoose from 'mongoose';
import { APIReference } from '../common/types';

type LanguageOptions = {
_id?: mongoose.Types.ObjectId;
choose: number;
from: APIReference[];
type: string;
};
import { APIReference, Choice } from '../common/types';

type Equipment = {
_id?: mongoose.Types.ObjectId;
equipment: APIReference;
quantity: number;
};

type StartingEquipmentOption = {
_id?: mongoose.Types.ObjectId;
equipment_category: APIReference;
};

type StartingEquipmentOptions = {
_id?: mongoose.Types.ObjectId;
choose: number;
from: StartingEquipmentOption[];
type: string;
};

type CharacteristicOptions = {
choose: number;
from: string[];
type: string;
};

type Ideal = {
desc: string;
alignments: APIReference[];
};

type IdealOptions = {
choose: number;
from: Ideal[];
type: string;
};

type Feature = {
name: string;
desc: string[];
Expand All @@ -53,13 +17,13 @@ export type Background = {
index: string;
name: string;
starting_proficiencies: APIReference[];
language_options: LanguageOptions;
language_options: Choice;
url: string;
starting_equipment: Equipment[];
starting_equipment_options: StartingEquipmentOptions[];
starting_equipment_options: Choice[];
feature: Feature;
personality_trait: CharacteristicOptions;
ideals: IdealOptions;
bonds: CharacteristicOptions;
flaws: CharacteristicOptions;
personality_trait: Choice;
ideals: Choice;
bonds: Choice;
flaws: Choice;
};
37 changes: 5 additions & 32 deletions src/models/class/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const { APIReference } = require('../common');
const { APIReference, Choice } = require('../common');

const Equipment = new Schema({
_id: false,
equipment: APIReference,
quantity: { type: Number, index: true },
});

const StartingEquipmentOption = new Schema({
_id: false,
equipment: APIReference,
quantity: { type: Number, index: true },
});

const StartingEquipmentOptions = new Schema({
_id: false,
choose: { type: Number, index: true },
from: [StartingEquipmentOption],
type: { type: String, index: true },
});

const ProficiencyChoice = new Schema({
_id: false,
choose: { type: Number, index: true },
from: [APIReference],
type: { type: String, index: true },
});

const SpellcastingInfo = new Schema({
_id: false,
desc: { type: [String], index: true },
Expand All @@ -47,19 +27,12 @@ const MultiClassingPrereq = new Schema({
minimum_score: { type: Number, index: true },
});

const MultiClassingPrereqOptions = new Schema({
_id: false,
choose: { type: Number, index: true },
from: [MultiClassingPrereq],
type: { type: String, index: true },
});

const MultiClassing = new Schema({
_id: false,
prerequisites: { type: [MultiClassingPrereq], default: undefined },
prerequisite_options: { type: MultiClassingPrereqOptions, default: undefined },
prerequisite_options: { type: Choice, default: undefined },
proficiencies: { type: [APIReference], default: undefined },
proficiency_choices: { type: [ProficiencyChoice], default: undefined },
proficiency_choices: { type: [Choice], default: undefined },
});

const Class = new Schema({
Expand All @@ -70,12 +43,12 @@ const Class = new Schema({
index: { type: String, index: true },
name: { type: String, index: true },
proficiencies: [APIReference],
proficiency_choices: [ProficiencyChoice],
proficiency_choices: [Choice],
saving_throws: [APIReference],
spellcasting: Spellcasting,
spells: { type: String, index: true },
starting_equipment: [Equipment],
starting_equipment_options: [StartingEquipmentOptions],
starting_equipment_options: [Choice],
subclasses: [APIReference],
url: { type: String, index: true },
});
Expand Down
28 changes: 5 additions & 23 deletions src/models/class/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as mongoose from 'mongoose';
import { APIReference } from '../common/types';
import { APIReference, Choice } from '../common/types';

type Equipment = {
equipment: APIReference;
Expand All @@ -11,18 +11,6 @@ type StartingEquipmentOption = {
quantity: number;
};

type StartingEquipmentOptions = {
choose: number;
from: StartingEquipmentOption[];
type: string;
};

type ProficiencyChoice = {
choose: number;
from: APIReference[];
type: string;
};

type SpellcastingInfo = {
desc: string[];
name: string;
Expand All @@ -39,17 +27,11 @@ type MultiClassingPrereq = {
minimum_score: number;
};

type MultiClassingPrereqOptions = {
choose: number;
from: MultiClassingPrereq[];
type: string;
};

type MultiClassing = {
prerequisites?: MultiClassingPrereq[];
prerequisite_options?: MultiClassingPrereqOptions;
prerequisite_options?: Choice;
proficiencies?: APIReference[];
proficiency_choices?: ProficiencyChoice[];
proficiency_choices?: Choice[];
};

export type Class = {
Expand All @@ -60,12 +42,12 @@ export type Class = {
index: string;
name: string;
proficiencies: APIReference[];
proficiency_choices: ProficiencyChoice[];
proficiency_choices: Choice[];
saving_throws: APIReference[];
spellcasting?: Spellcasting;
spells?: string;
starting_equipment?: Equipment[];
starting_equipment_options: StartingEquipmentOptions[];
starting_equipment_options: Choice[];
subclasses: APIReference[];
url: string;
};
Loading

0 comments on commit c33e2b8

Please sign in to comment.