Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
corps-directory
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fhurtado14
corps-directory
Commits
43c81e09
Commit
43c81e09
authored
4 months ago
by
Federico Hurtado
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/main' into feature/activity-logger
parents
a72cbaab
27d91ba9
No related branches found
Branches containing commit
No related tags found
1 merge request
!8
Feature/activity logger
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/config/database/databaseInitializer.js
+104
-0
104 additions, 0 deletions
backend/config/database/databaseInitializer.js
backend/repository/involvementRepository.js
+133
-0
133 additions, 0 deletions
backend/repository/involvementRepository.js
with
237 additions
and
0 deletions
backend/config/database/databaseInitializer.js
+
104
−
0
View file @
43c81e09
...
...
@@ -6,6 +6,12 @@ const {
addStateIfNotExists
,
checkTableExistence
,
}
=
require
(
"
../../repository/stateRepository
"
);
const
{
addInvolvementTypeIfNotExists
,
addInvolvementIfNotExists
,
checkInvolvementTypeTableExistence
,
checkInvolvementLookupTableExistence
,
}
=
require
(
"
../../repository/involvementRepository
"
);
/*
Class responsible for populating the database
...
...
@@ -133,11 +139,109 @@ class DatabaseInitializer {
}
}
/*
Creates all the involvement types
*/
async
initializeInvolvementTypes
()
{
await
checkInvolvementTypeTableExistence
();
// Ensure the table exists
const
involvementTypes
=
[
"
Asian American Cadet Organization
"
,
"
Black Cadet Organization
"
,
"
Cadet Alumni Team
"
,
"
Cadet Language Organization
"
,
"
Cadets for a Cause
"
,
"
Coast Guard Auxiliary
"
,
"
Color Guard
"
,
"
Conrad Cavalry
"
,
"
Corps Marksmanship Team
"
,
"
Eagle Scout Association
"
,
"
EMT Staff
"
,
"
Esprit de Corps
"
,
"
Executive Committee
"
,
"
Fenix (Latin Cadets)
"
,
"
Gregory Guard
"
,
"
Growley Team
"
,
"
Hall Council
"
,
"
Helping Educate Regarding Orientation (HERO)
"
,
"
Historian Staff
"
,
"
Honor Court
"
,
"
Inspector General Staff
"
,
"
Men's Basketball
"
,
"
O-Course Committee
"
,
"
Ordinance Staff
"
,
"
Rappelling Tower Committee
"
,
"
Recruiting Staff
"
,
"
Sash and Saber Honor Society
"
,
"
Signal Corps
"
,
"
Skipper Crew
"
,
"
Society of American Military Engineers
"
,
"
VPI Battalion
"
,
"
VTCC Cyber Team
"
,
"
Women's Basketball
"
,
];
for
(
const
type
of
involvementTypes
)
{
await
addInvolvementTypeIfNotExists
(
type
);
// Add each involvement type
}
}
/*
Creates all the involvement lookups directly based on the defined involvement types
*/
async
initializeInvolvementLookups
()
{
await
checkInvolvementLookupTableExistence
();
// Ensure the lookup table exists
// Define lookup entries with type IDs (these IDs should correspond to your actual involvement type IDs)
const
involvementLookups
=
[
{
involvementTypeId
:
1
},
// Asian American Cadet Organization
{
involvementTypeId
:
2
},
// Black Cadet Organization
{
involvementTypeId
:
3
},
// Cadet Alumni Team
{
involvementTypeId
:
4
},
// Cadet Language Organization
{
involvementTypeId
:
5
},
// Cadets for a Cause
{
involvementTypeId
:
6
},
// Coast Guard Auxiliary
{
involvementTypeId
:
7
},
// Color Guard
{
involvementTypeId
:
8
},
// Conrad Cavalry
{
involvementTypeId
:
9
},
// Corps Marksmanship Team
{
involvementTypeId
:
10
},
// Eagle Scout Association
{
involvementTypeId
:
11
},
// EMT Staff
{
involvementTypeId
:
12
},
// Esprit de Corps
{
involvementTypeId
:
13
},
// Executive Committee
{
involvementTypeId
:
14
},
// Fenix (Latin Cadets)
{
involvementTypeId
:
15
},
// Gregory Guard
{
involvementTypeId
:
16
},
// Growley Team
{
involvementTypeId
:
17
},
// Hall Council
{
involvementTypeId
:
18
},
// Helping Educate Regarding Orientation (HERO)
{
involvementTypeId
:
19
},
// Historian Staff
{
involvementTypeId
:
20
},
// Honor Court
{
involvementTypeId
:
21
},
// Inspector General Staff
{
involvementTypeId
:
22
},
// Men’s Basketball
{
involvementTypeId
:
23
},
// O-Course Committee
{
involvementTypeId
:
24
},
// Ordinance Staff
{
involvementTypeId
:
25
},
// Rappelling Tower Committee
{
involvementTypeId
:
26
},
// Recruiting Staff
{
involvementTypeId
:
27
},
// Sash and Saber Honor Society
{
involvementTypeId
:
28
},
// Signal Corps
{
involvementTypeId
:
29
},
// Skipper Crew
{
involvementTypeId
:
30
},
// Society of American Military Engineers
{
involvementTypeId
:
31
},
// VPI Battalion
{
involvementTypeId
:
32
},
// VTCC Cyber Team
{
involvementTypeId
:
33
},
// Women’s Basketball
];
for
(
const
entry
of
involvementLookups
)
{
await
addInvolvementIfNotExists
(
entry
.
involvementTypeId
);
// Add entry to involvementLookup
}
}
async
initializeAll
()
{
await
this
.
testDBConnection
();
await
this
.
initializeRoles
();
await
this
.
initializeTestUsers
();
await
this
.
initializeStates
();
await
this
.
initializeInvolvementTypes
();
await
this
.
initializeInvolvementLookups
();
console
.
log
(
"
database init completed.
"
);
}
...
...
This diff is collapsed.
Click to expand it.
backend/repository/involvementRepository.js
+
133
−
0
View file @
43c81e09
const
{
pool
}
=
require
(
"
../config/database/database.config
"
);
/*
Class responsible for making queries to the
involvementLookup and involvementType database.
*/
/*
Function to add an involvement type to the database
*/
async
function
addInvolvementTypeIfNotExists
(
description
)
{
console
.
log
(
"
adding involvement type:
"
,
description
);
// Don't add involvement type if it exists
const
existingType
=
await
getInvolvementType
(
description
);
if
(
existingType
)
{
console
.
log
(
"
Involvement type already exists:
"
,
description
);
return
;
}
// Insert SQL query
const
query
=
`INSERT INTO involvementType (description) VALUES (?)`
;
// Attempt to insert involvement type into table
try
{
await
pool
.
query
(
query
,
[
description
]);
console
.
log
(
`Successfully added involvement type:
${
description
}
`
);
}
catch
(
error
)
{
console
.
error
(
`Error adding involvement type:
${
description
}
`
,
error
);
throw
error
;
}
}
async
function
getInvolvementType
(
description
)
{
// SQL query to get a certain involvement type
const
query
=
"
SELECT * FROM involvementType WHERE description = ?
"
;
try
{
console
.
log
(
"
Getting involvement type:
"
,
description
);
const
[
rows
]
=
await
pool
.
query
(
query
,
[
description
]);
if
(
rows
.
length
>
0
)
{
console
.
log
(
"
Found involvement type:
"
,
description
);
return
rows
[
0
];
}
else
{
console
.
log
(
"
Involvement type not found:
"
,
description
);
return
null
;
}
}
catch
(
error
)
{
console
.
error
(
`Error fetching involvement type
${
description
}
:`
,
error
);
throw
error
;
}
}
/*
Function to add an involvement to the involvementLookup table
*/
async
function
addInvolvementIfNotExists
(
involvementTypeId
)
{
console
.
log
(
"
Adding involvement for type ID:
"
,
involvementTypeId
);
// Don't add involvement if it exists
const
existingInvolvement
=
await
getInvolvement
(
involvementTypeId
);
if
(
existingInvolvement
)
{
console
.
log
(
"
Involvement already exists:
"
,
involvementTypeId
);
return
;
}
// Insert SQL query
const
query
=
`INSERT INTO involvementLookup (involvementType) VALUES (?)`
;
// Attempt to insert involvement into table
try
{
await
pool
.
query
(
query
,
[
involvementTypeId
]);
console
.
log
(
`Successfully added involvement with type ID:
${
involvementTypeId
}
`
);
}
catch
(
error
)
{
console
.
error
(
`Error adding involvement with type ID:
${
involvementTypeId
}
`
,
error
);
throw
error
;
}
}
async
function
getInvolvement
(
involvementType
)
{
// SQL query to get a certain involvement
const
query
=
"
SELECT * FROM involvementLookup WHERE involvementType = ?
"
;
try
{
console
.
log
(
"
Getting involvement:
"
,
involvementType
);
const
[
rows
]
=
await
pool
.
query
(
query
,
[
involvementType
]);
if
(
rows
.
length
>
0
)
{
console
.
log
(
"
Found involvement:
"
,
involvementType
);
return
rows
[
0
];
}
else
{
console
.
log
(
"
Involvement not found:
"
,
involvementType
);
return
null
;
}
}
catch
(
error
)
{
console
.
error
(
`Error fetching involvement
${
involvementType
}
:`
,
error
);
throw
error
;
}
}
async
function
checkInvolvementTypeTableExistence
()
{
try
{
const
[
rows
]
=
await
pool
.
query
(
"
SHOW TABLES LIKE 'involvementType'
"
);
if
(
rows
.
length
>
0
)
{
console
.
log
(
"
Table `involvementType` exists
"
);
}
else
{
console
.
log
(
"
Table `involvementType` does not exist
"
);
}
}
catch
(
error
)
{
console
.
error
(
"
Error checking involvementType table existence:
"
,
error
);
}
}
async
function
checkInvolvementLookupTableExistence
()
{
try
{
const
[
rows
]
=
await
pool
.
query
(
"
SHOW TABLES LIKE 'involvementLookup'
"
);
if
(
rows
.
length
>
0
)
{
console
.
log
(
"
Table `involvementLookup` exists
"
);
}
else
{
console
.
log
(
"
Table `involvementLookup` does not exist
"
);
}
}
catch
(
error
)
{
console
.
error
(
"
Error checking involvementLookup table existence:
"
,
error
);
}
}
module
.
exports
=
{
checkInvolvementTypeTableExistence
,
checkInvolvementLookupTableExistence
,
addInvolvementTypeIfNotExists
,
getInvolvementType
,
addInvolvementIfNotExists
,
getInvolvement
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment