-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RQ - Updated previous classes/methods with new DB changes
- Loading branch information
1 parent
eb73900
commit 4b385f2
Showing
27 changed files
with
641 additions
and
654 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as EntityDefsModel from './entityDefs.model'; | ||
import * as EntityDefsServices from './entityDefs.service'; | ||
|
||
/** | ||
* Get logged in User's roster | ||
*/ | ||
export const getUserEntityDefs = async (user_fk: number) : Promise<EntityDefsModel.EntityDef> => { | ||
return await EntityDefsServices.getUserEntityDefsByUserId(user_fk); | ||
}; | ||
|
||
/** | ||
* Get logged in User's party roster | ||
*/ | ||
export const getUserPartyEntityDefs = async (user_fk: number) : Promise<EntityDefsModel.EntityDef[]> => { | ||
return EntityDefsServices.getUserPartyEntityDefs(user_fk); | ||
}; | ||
|
||
/** | ||
* gets roster unit by user id and unit id | ||
*/ | ||
export const getUnitByUserIdAndUnitId = async (user_fk: EntityDefsModel.EntityDef['user_fk'], unit_id: EntityDefsModel.EntityDef['unit_id']) => { | ||
return await EntityDefsServices.getUnitByUserIdAndUnitId(user_fk, unit_id); | ||
}; | ||
|
||
/** | ||
* Get User's Entities max unit_id by unit id | ||
*/ | ||
export const getEntityMaxUnitId = async (user_fk: number, unit_id: string): Promise<EntityDefsModel.EntityDef> => { | ||
return await EntityDefsServices.getEntityMaxUnitId(user_fk, unit_id); | ||
}; | ||
|
||
/** | ||
* gets user's roster ID based on unit id provided | ||
*/ | ||
export const getUserEntDefByUnitId = async (user_fk: number, unit_id: string) => { | ||
return await EntityDefsServices.getUserEntDefByUnitId(user_fk, unit_id); | ||
}; | ||
|
||
/** | ||
* Insert Purchasable Unit data to Roster - triggers when hiring new units | ||
*/ | ||
export const insertUserEntity = async (new_entity: EntityDefsModel.AddEntityDef) => { | ||
await EntityDefsServices.insertUserEntity(new_entity); | ||
}; | ||
|
||
/** | ||
* updates roster's name | ||
*/ | ||
export const updateUnitName = async (user_fk: EntityDefsModel.EntityDef['user_fk'], unit_id: EntityDefsModel.EntityDef['unit_id'], name: EntityDefsModel.EntityDef['name']) => { | ||
return await EntityDefsServices.updateUnitName(user_fk, unit_id, name); | ||
}; | ||
|
||
/** | ||
* updates roster's entity class | ||
*/ | ||
export const updateUnitClass = async (user_fk: EntityDefsModel.EntityDef['user_fk'], unit_id: EntityDefsModel.EntityDef['unit_id'], entity_class: EntityDefsModel.EntityDef['entity_class']) => { | ||
return await EntityDefsServices.updateUnitClass(user_fk, unit_id, entity_class); | ||
}; | ||
|
||
/** | ||
* Delete user's Roster / Unit | ||
*/ | ||
export const deleteEntityDef = async (user_fk: EntityDefsModel.EntityDef['user_fk'], unit_id: EntityDefsModel.EntityDef['unit_id']) => { | ||
await EntityDefsServices.deleteEntityDef(user_fk, unit_id); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export class EntityDef { | ||
id: number; | ||
user_fk: number; | ||
classs: string; | ||
unit_id: string; | ||
entity_class: string; | ||
name: string; | ||
appearance_acquires: number; | ||
appearance_index: number; | ||
|
||
public constructor(id: number, user_fk: number, unit_id: string, entity_class: string, name: string, appearance_acquires: number, appearance_index: number) { | ||
this.id = id; | ||
this.user_fk = user_fk; | ||
this.classs = "EntityDef"; | ||
this.unit_id = unit_id; | ||
this.entity_class = entity_class; | ||
this.name = name; | ||
this.appearance_acquires = appearance_acquires; | ||
this.appearance_index = appearance_index; | ||
}; | ||
} | ||
|
||
export class AddEntityDef { | ||
user_fk: number; | ||
classs = "EntityDef"; | ||
unit_id: string; | ||
entity_class: string; | ||
name: string; | ||
appearance_acquires: number; | ||
appearance_index: number; | ||
|
||
public constructor(user_fk: number, unit_id: string, entity_class: string, name: string) { | ||
this.user_fk = user_fk; | ||
this.unit_id = unit_id; | ||
this.entity_class = entity_class; | ||
this.name = name; | ||
this.appearance_acquires = 0; | ||
this.appearance_index = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
export const EntityDefQueries = { | ||
GetUserEntityDefsByUserId: | ||
` | ||
SELECT | ||
id, | ||
unit_id, | ||
entity_class, | ||
name, | ||
start_date, | ||
appearance_acquires, | ||
appearance_index | ||
FROM db.EntityDef | ||
WHERE | ||
user_fk = ?; | ||
`, | ||
|
||
GetUserPartyEntityDefsByUserId: | ||
` | ||
SELECT | ||
ed.id, | ||
ed.unit_id, | ||
ed.entity_class, | ||
ed.name, | ||
ed.appearance_acquires, | ||
ed.appearance_index | ||
FROM db.Parties p | ||
LEFT JOIN db.EntityDef ed ON p.unit_id = ed.unit_id | ||
WHERE p.user_fk = ? AND r.user_fk = ?; | ||
`, | ||
|
||
GetUnitByUserIdAndUnitId: | ||
` | ||
SELECT | ||
* | ||
FROM db.EntityDef as ed | ||
WHERE | ||
ed.user_fk = ? and ed.unit_id = ?; | ||
`, | ||
|
||
GetEntityMaxUnitId: | ||
` | ||
SELECT | ||
* | ||
FROM db.EntityDef | ||
WHERE | ||
user_fk = ? | ||
AND | ||
unit_id LIKE ? | ||
ORDER BY unit_id DESC LIMIT 1; | ||
`, | ||
|
||
GetUserEntDefByUnitId: | ||
` | ||
SELECT | ||
id | ||
FROM db.EntityDef | ||
WHERE user_fk = ? | ||
AND unit_id = ?; | ||
`, | ||
|
||
InsertUserEntity: | ||
` | ||
INSERT INTO db.EntityDef | ||
(user_fk, unit_id, entity_class, name, appearance_acquires, appearance_index) | ||
VALUES | ||
(?, ?, ?, ?, ?, ?); | ||
`, | ||
|
||
UpdateEntity_Name: | ||
` | ||
UPDATE db.EntityDef as ed | ||
SET ed.name = ? | ||
WHERE | ||
user_fk = ? | ||
AND | ||
unit_id = ?; | ||
`, | ||
|
||
UpdateEntity_EntityClass: | ||
` | ||
UPDATE db.EntityDef as ed | ||
SET ed.entity_class = ? | ||
WHERE | ||
user_fk = ? | ||
AND | ||
unit_id = ?; | ||
`, | ||
|
||
DeleteUserEntityUnit: | ||
` | ||
DELETE FROM db.EntityDef | ||
WHERE | ||
user_fk = ? | ||
AND | ||
unit_id = ? | ||
`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { execute } from "../mysql.connector"; | ||
|
||
import * as EntityDefQueries from "./entityDefs.queries"; | ||
import * as EntityDefModels from "./entityDefs.model"; | ||
|
||
/** | ||
* gets user's party based on id provided | ||
*/ | ||
export const getUserEntityDefsByUserId = async (user_fk: EntityDefModels.EntityDef['user_fk']) => { | ||
return execute<EntityDefModels.EntityDef>(EntityDefQueries.EntityDefQueries.GetUserEntityDefsByUserId, [user_fk]); | ||
}; | ||
|
||
/** | ||
* Get logged in User's party roster | ||
*/ | ||
export const getUserPartyEntityDefs = async (user_fk: EntityDefModels.EntityDef['user_fk']) => { | ||
return execute<EntityDefModels.EntityDef[]>(EntityDefQueries.EntityDefQueries.GetUserPartyEntityDefsByUserId, [user_fk, user_fk]); | ||
}; | ||
|
||
/** | ||
* gets roster unit by user id and unit id | ||
*/ | ||
export const getUnitByUserIdAndUnitId = async (user_fk: EntityDefModels.EntityDef['user_fk'], unit_id: EntityDefModels.EntityDef['unit_id']) => { | ||
return execute<EntityDefModels.EntityDef>(EntityDefQueries.EntityDefQueries.GetUnitByUserIdAndUnitId, [user_fk, unit_id]); | ||
}; | ||
|
||
/** | ||
* Get User's Entity Def max unit_id by unit id | ||
*/ | ||
export const getEntityMaxUnitId = async (user_fk: number, unit_id: string): Promise<EntityDefModels.EntityDef> => { | ||
return execute<EntityDefModels.EntityDef>(EntityDefQueries.EntityDefQueries.GetEntityMaxUnitId, [user_fk, unit_id]); | ||
}; | ||
|
||
/** | ||
* gets user's entity def ID based on unit id provided | ||
*/ | ||
export const getUserEntDefByUnitId = async (user_fk: number, unit_id: string) => { | ||
return execute<number>(EntityDefQueries.EntityDefQueries.GetUserEntDefByUnitId, [user_fk, unit_id]); | ||
}; | ||
|
||
/** | ||
* Insert Purchasable Unit data to Roster - triggers when hiring new units | ||
*/ | ||
export const insertUserEntity = async (new_entity: EntityDefModels.AddEntityDef) => { | ||
return execute<EntityDefModels.EntityDef>(EntityDefQueries.EntityDefQueries.InsertUserEntity, [new_entity.user_fk, new_entity.unit_id, new_entity.entity_class, new_entity.name, new_entity.appearance_acquires, new_entity.appearance_index]); | ||
}; | ||
|
||
/** | ||
* updates roster's name | ||
*/ | ||
export const updateUnitName = async (user_fk: EntityDefModels.EntityDef['user_fk'], unit_id: EntityDefModels.EntityDef['unit_id'], name: EntityDefModels.EntityDef['name']) => { | ||
return execute<EntityDefModels.EntityDef>(EntityDefQueries.EntityDefQueries.UpdateEntity_Name, [name, user_fk, unit_id]); | ||
}; | ||
|
||
/** | ||
* updates roster's entity class | ||
*/ | ||
export const updateUnitClass = async (user_fk: EntityDefModels.EntityDef['user_fk'], unit_id: EntityDefModels.EntityDef['unit_id'], entity_class: EntityDefModels.EntityDef['entity_class']) => { | ||
return execute<EntityDefModels.EntityDef>(EntityDefQueries.EntityDefQueries.UpdateEntity_EntityClass, [entity_class, user_fk, unit_id]); | ||
}; | ||
|
||
/** | ||
* Delete user's Roster / Unit | ||
*/ | ||
export const deleteEntityDef = async (user_fk: EntityDefModels.EntityDef['user_fk'], unit_id: EntityDefModels.EntityDef['unit_id']) => { | ||
execute<EntityDefModels.EntityDef>(EntityDefQueries.EntityDefQueries.DeleteUserEntityUnit, [user_fk, unit_id]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export class Stat { | ||
id: number; | ||
stat: string; | ||
|
||
constructor(id: number, stat: string) { | ||
this.id = id; | ||
this.stat = stat; | ||
export class Party { | ||
user_fk: number; | ||
unit_id: string; | ||
constructor(user_fk: number, unit_id: string) { | ||
this.user_fk = user_fk; | ||
this.unit_id = unit_id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
export const StatsQueries = { | ||
GetStatByName: ` | ||
SELECT | ||
export const PartiesQueries = { | ||
GetUserPartyByUserId: | ||
` | ||
SELECT | ||
* | ||
FROM banner_saga_factions.stats | ||
WHERE stat = ?; | ||
` | ||
}; | ||
FROM db.Parties | ||
WHERE | ||
user_fk = ?; | ||
`, | ||
|
||
InsertUserParty: | ||
` | ||
INSERT INTO db.Parties | ||
(user_fk, unit_id) | ||
VALUES | ||
(?, ?); | ||
`, | ||
|
||
DeleteUserParty: | ||
` | ||
DELETE FROM db.Parties | ||
WHERE | ||
user_fk = ? | ||
`, | ||
}; |
Oops, something went wrong.