Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atmakuja db changes #10

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
RQ - All updates Pre-DB changes
  • Loading branch information
Red-Pyramid-Head authored and Pieloaf committed Nov 21, 2023
commit bc94ef2d4619ca5459055f37befc07ce6124db88
1,271 changes: 1,271 additions & 0 deletions data/acc - Copy.json

Large diffs are not rendered by default.

718 changes: 2 additions & 716 deletions data/acc.json

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions src/api/utils/purchasableUnits/purchasableUnits.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as PurchasableUnitsModels from './purchasableUnits.model';
import * as PurchasableUnitsServices from './purchasableUnits.service';
import * as UsersModels from '../users/users.model';

/**
* Get all purchasable units
*/
export const getPurchasableUnits = async (): Promise<PurchasableUnitsModels.PurchasableUnit[]> => {
return await PurchasableUnitsServices.getPurchasableUnits();
};

/**
* Get purchasable unit by def Id
*/
export const getPurchasableUnitByDefId = async (def_id: string): Promise<PurchasableUnitsModels.PurchasableUnit> => {
return await PurchasableUnitsServices.getPurchasableUnitByDefId(def_id);
};

/**
* Get User's Roster max unit_id by unit id
*/
export const getRosterMaxUnitId = async (user_fk: number, unit_id: string): Promise<UsersModels.Roster> => {
return await PurchasableUnitsServices.getRosterMaxUnitId(user_fk, unit_id);
};

/**
* gets user's roster ID based on unit id provided
*/
export const getUserRosterByUnitId = async (user_fk: number, unit_id: string) => {
return await PurchasableUnitsServices.getUserRosterByUnitId(user_fk, unit_id);
};

/**
* Get purchasable unit stats data (without IDs) based on id provided
*/
export const getPurchasableUnitStats = async (purchasable_unit_fk: number) => {
try {
const purchasableUnitStats = await PurchasableUnitsServices.getPurchasableUnitStatsById(purchasable_unit_fk);
return purchasableUnitStats;
} catch (error) {
return [];
}
};

/**
* Get purchasable unit stats data (with IDs) based on id provided
*/
export const getPurchasableUnitStatsRaw = async (purchasable_unit_fk: number) => {
try {
const purchasableUnitStats = await PurchasableUnitsServices.getPurchasableUnitStatsRawById(purchasable_unit_fk);
return purchasableUnitStats;
} catch (error) {
return [];
}
};

/**
* Insert Purchasable Unit data to Roster - triggers when hiring new units
*/
export const insertUserRoster = async (new_roster: UsersModels.AddRoster) => {
await PurchasableUnitsServices.insertUserRoster(new_roster);
};

/**
* Insert Purchasable Unit Stat data to Roster - triggers when hiring new units
*/
export const insertUserRosterStat = async (roster_fk: number, stat_fk: number, value: number) => {
await PurchasableUnitsServices.insertUserRosterStat(roster_fk, stat_fk, value);
};
58 changes: 58 additions & 0 deletions src/api/utils/purchasableUnits/purchasableUnits.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export class PurchasableUnit {
id: number;
pu_class: string;
def_class: string;
def_id: string;
def_entity_class: string;
def_auto_level: number;
def_start_date: number;
def_appearance_acquires: number;
def_appearance_index: number;
limit: number;
cost: number;
comment: string;

constructor(id: number, pu_class: string, def_class: string, def_id: string, def_entity_class: string,
def_auto_level: number, def_start_date: number, def_appearance_acquires: number, def_appearance_index: number, limit: number, cost: number, comment: string) {
this.id = id;
this.pu_class = pu_class;
this.def_class = def_class;
this.def_id = def_id;
this.def_entity_class = def_entity_class;
this.def_auto_level = def_auto_level;
this.def_start_date = def_start_date;
this.def_appearance_acquires = def_appearance_acquires;
this.def_appearance_index = def_appearance_index;
this.limit = limit;
this.cost = cost;
this.comment = comment;
}
}

export class PurchasableUnitStat {
purchasable_unit_fk: number;
classs: string;
stat: string;
value: number;

constructor(purchasable_unit_fk: number, classs: string, stat: string, value: number) {
this.purchasable_unit_fk = purchasable_unit_fk;
this.classs = classs;
this.stat = stat;
this.value = value;
}
}

export class PurchasableUnitStatRaw {
purchasable_unit_fk: number;
class_fk: number;
stat_fk: number;
value: number;

constructor(purchasable_unit_fk: number, class_fk: number, stat_fk: number, value: number) {
this.purchasable_unit_fk = purchasable_unit_fk;
this.class_fk = class_fk;
this.stat_fk = stat_fk;
this.value = value;
}
}
67 changes: 67 additions & 0 deletions src/api/utils/purchasableUnits/purchasableUnits.queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
export const PurchasableUnitsQueries = {
GetPurchasableUnits: `
SELECT
pu.id, c1.class as pu_class, c2.class as def_class, def_id, def_entity_class, def_auto_level, def_start_date, def_appearance_acquires, def_appearance_index, pu.limit, cost, comment
FROM banner_saga_factions.purchasable_units as pu
LEFT JOIN banner_saga_factions.classes c1 ON pu.class_fk = c1.id
LEFT JOIN banner_saga_factions.classes c2 ON pu.def_class_fk = c2.id;
`,

GetPurchasableUnitByDefId: `
SELECT
*
FROM banner_saga_factions.purchasable_units as pu
WHERE def_id = ?
`,

GetRosterMaxUnitId: `
SELECT
*
FROM banner_saga_factions.rosters
WHERE user_fk = ?
AND unit_id LIKE ?
ORDER BY unit_id DESC LIMIT 1;
`,

GetUserRosterByUnitId: `
SELECT
id
FROM banner_saga_factions.rosters
WHERE user_fk = ?
AND unit_id = ?;
`,

GetPurchasableUnitStatsById: `
SELECT
c.class, s.stat, value
FROM banner_saga_factions.purchasable_unit_stats as pus
LEFT JOIN banner_saga_factions.classes c ON pus.class_fk = c.id
LEFT JOIN banner_saga_factions.stats s ON pus.stat_fk = s.id
WHERE
pus.purchasable_unit_fk = ?
ORDER BY stat_fk ASC;
`,

GetPurchasableUnitStatsRawById: `
SELECT
*
FROM banner_saga_factions.purchasable_unit_stats
WHERE
purchasable_unit_fk = ?
ORDER BY stat_fk ASC;
`,

InsertUserRoster: `
INSERT INTO banner_saga_factions.rosters
(user_fk, class_fk, unit_id, entity_class, name, appearance_acquires, appearance_index)
VALUES
(?, ?, ?, ?, ?, ?, ?);
`,

InsertUserRosterStat: `
INSERT INTO banner_saga_factions.roster_stats
(roster_fk, class_fk, stat_fk, value)
VALUES
(?, ?, ?, ?);
`
};
61 changes: 61 additions & 0 deletions src/api/utils/purchasableUnits/purchasableUnits.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { execute } from "../mysql.connector";

import { PurchasableUnitsQueries } from "./purchasableUnits.queries";
import { PurchasableUnit, PurchasableUnitStat, PurchasableUnitStatRaw } from "./purchasableUnits.model";
import * as UsersModels from '../users/users.model';

/**
* gets all purchasable units
*/
export const getPurchasableUnits = async () => {
return execute<PurchasableUnit[]>(PurchasableUnitsQueries.GetPurchasableUnits, []);
};

/**
* gets purchasable unit by def id
*/
export const getPurchasableUnitByDefId = async (def_id: PurchasableUnit['def_id']) => {
return execute<PurchasableUnit>(PurchasableUnitsQueries.GetPurchasableUnitByDefId, [def_id]);
};

/**
* Get User's Roster max unit_id by unit id
*/
export const getRosterMaxUnitId = async (user_fk: number, unit_id: string): Promise<UsersModels.Roster> => {
return execute<UsersModels.Roster>(PurchasableUnitsQueries.GetRosterMaxUnitId, [user_fk, unit_id]);
};

/**
* gets user's roster ID based on unit id provided
*/
export const getUserRosterByUnitId = async (user_fk: number, unit_id: string) => {
return execute<number>(PurchasableUnitsQueries.GetUserRosterByUnitId, [user_fk, unit_id]);
};

/**
* gets purchasable unit's stats
*/
export const getPurchasableUnitStatsById = async (purchasable_unit_fk: PurchasableUnitStat['purchasable_unit_fk']) => {
return execute<PurchasableUnitStat[]>(PurchasableUnitsQueries.GetPurchasableUnitStatsById, [purchasable_unit_fk]);
};

/**
* gets purchasable unit's stats
*/
export const getPurchasableUnitStatsRawById = async (purchasable_unit_fk: number) => {
return execute<PurchasableUnitStatRaw[]>(PurchasableUnitsQueries.GetPurchasableUnitStatsRawById, [purchasable_unit_fk]);
};

/**
* Insert Purchasable Unit data to Roster - triggers when hiring new units
*/
export const insertUserRoster = async (new_roster: UsersModels.AddRoster) => {
return execute<UsersModels.Roster>(PurchasableUnitsQueries.InsertUserRoster, [new_roster.user_fk, new_roster.class_fk, new_roster.unit_id, new_roster.entity_class, new_roster.name, new_roster.appearance_acquires, new_roster.appearance_index]);
};

/**
* Insert Purchasable Unit Stat data to Roster - triggers when hiring new units
*/
export const insertUserRosterStat = async (roster_fk: number, stat_fk: number, value: number) => {
return execute<UsersModels.Roster>(PurchasableUnitsQueries.InsertUserRosterStat, [roster_fk, 4, stat_fk, value]);
};
9 changes: 9 additions & 0 deletions src/api/utils/stats/stats.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as StatsModel from './stats.model';
import * as StatsServices from './stats.service';

/**
* get stat by name
*/
export const getStatByName = async (stat: string): Promise<StatsModel.Stat> => {
return await StatsServices.getStatByName(stat);
};
9 changes: 9 additions & 0 deletions src/api/utils/stats/stats.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class Stat {
id: number;
stat: string;

constructor(id: number, stat: string) {
this.id = id;
this.stat = stat;
}
}
8 changes: 8 additions & 0 deletions src/api/utils/stats/stats.queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const StatsQueries = {
GetStatByName: `
SELECT
*
FROM banner_saga_factions.stats
WHERE stat = ?;
`
};
11 changes: 11 additions & 0 deletions src/api/utils/stats/stats.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { execute } from "../mysql.connector";

import * as StatsQueries from "./stats.queries";
import * as StatsModels from "./stats.model";

/**
* get stat by name
*/
export const getStatByName = async (stat: string) => {
return execute<StatsModels.Stat>(StatsQueries.StatsQueries.GetStatByName, [stat]);
};
Loading