Skip to content

Commit

Permalink
Merge pull request #11 from OurFreeLight/dev
Browse files Browse the repository at this point in the history
chore: removed forced seeding from dev builds;
  • Loading branch information
ncoonrod committed Mar 4, 2024
2 parents dd0a2a9 + 6d0994f commit 9e2f079
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "@hotstaq/userroute",
"description": "A user route for HotStaq. Allows users to be created/edited/deleted securely.",
"version": "0.4.9",
"version": "0.5.0",
"main": "build/src/index.js",
"scripts": {
"test": "hotstaq --dev --env-file .env run --server-type api --api-test",
Expand Down
92 changes: 55 additions & 37 deletions src/User.ts
Expand Up @@ -297,46 +297,64 @@ export class User implements IUser
logOutDate DATETIME DEFAULT NULL,
PRIMARY KEY (id)
)`);
}

/**
* Checks if the users table is empty.
*
* @returns Returns true if the users table is empty.
*/
static async checkForEmptyUsers (db: HotDBMySQL): Promise<boolean>
{
let results: MySQLResults = await db.queryOne (`select COUNT(*) from users;`);

if (results.results["COUNT(*)"] < 1)
return (true);

return (false);
}

if (debug == true)
/**
* Seed the users table.
*
* @param testPlayers The test players to seed. If the array is empty, it will use the default test players.
*/
static async seedUsers (db: HotDBMySQL, testPlayers: User[] = []): Promise<void>
{
if (testPlayers.length < 1)
{
let results: MySQLResults = await db.queryOne (`select COUNT(*) from users;`);
testPlayers = [
new User ({
firstName: "John",
lastName: "Doe",
displayName: "Test1",
email: "test1@freelight.org",
password: "a867h398jdg",
verified: true
}),
new User ({
firstName: "Jane",
lastName: "Smith",
displayName: "Test2",
email: "test2@freelight.org",
password: "ai97w3a98w3498",
verified: true }),
new User ({
userType: "admin",
firstName: "Bob",
lastName: "Derp",
displayName: "Admin1",
email: "admin1@freelight.org",
password: "a98j3w987aw3h47u",
verified: true })
];
}

if (results.results["COUNT(*)"] < 1)
{
let testPlayers = [
new User ({
firstName: "John",
lastName: "Doe",
displayName: "Test1",
email: "test1@freelight.org",
password: "a867h398jdg",
verified: true
}),
new User ({
firstName: "Jane",
lastName: "Smith",
displayName: "Test2",
email: "test2@freelight.org",
password: "ai97w3a98w3498",
verified: true }),
new User ({
userType: "admin",
firstName: "Bob",
lastName: "Derp",
displayName: "Admin1",
email: "admin1@freelight.org",
password: "a98j3w987aw3h47u",
verified: true })
];

for (let iIdx = 0; iIdx < testPlayers.length; iIdx++)
{
let testPlayer = testPlayers[iIdx];

await testPlayer.register (db);
}
}
for (let iIdx = 0; iIdx < testPlayers.length; iIdx++)
{
let testPlayer = testPlayers[iIdx];

await testPlayer.register (db);
}
}

Expand Down

0 comments on commit 9e2f079

Please sign in to comment.