This is the backend for the the challenge. Check out the front-end Here.
To install dependencies:
bun install
To run app, (http://localhost:5500):
bun run dev
To migrate database (if you decide to delete "sqlite.db"):
bun run ./src/database/migrate.ts
Currently Implemented Routes Include:
Requests-Releated:
Route | Parameter | Body | Functionality |
---|---|---|---|
/uploadData | JSON: request[] | inserts data into DB. returns time taken. | |
/getAllRequests | returns all requests in DB. | ||
/getRequest/:Requestid | RequestID | returns request with specified RequestID. | |
/getAllAccounts | returns all accountRequests in DB. | ||
/getAccount/:Requestid | RequestID | returns accountRequest with specified RequestID. | |
/getAllActivityRequests | returns all activityRequests in DB. | ||
/getActivityRequest/:Requestid | RequestID | returns activityRequest with specified RequestID. |
Permissions-Releated:
Route | Parameter | Body | Functionality |
---|---|---|---|
/getAccountPermissions/:accountID | AccountID | returns specified account permissions as string[]. | |
/addPermission/:name | Name | inserts permission with specified name. | |
/getAllPermissions | returns all permissions in DB. |
Activities-Releated:
Route | Parameter | Body | Functionality |
---|---|---|---|
/getCompanyActivities/:id | ActivityRequestID | returns specified company activities as string[]. | |
/addActivity/:name | Name | inserts activity with specified name. | |
/getAllActivities | returns all activities in DB. |
There are many rules to inserting data into the database, some include:
- Request ID already exists in database.
- Request Type not in range [1-5].
- Request Status not in range [1-3].
- Row data does not match any request type data structure.
- Adding Account with permission not in database (have to add it first).
- Adding CompanyActivity with activity not in database (have to add it first).
- Adding Permission using a name that already exists (Permission names are unique).
- Adding Activity using a name that already exists (Activity names are unique).
Violating any of the rules will result in omitting the row trying to insert. and no response will be provided to the front-end, the code will continue to add the following rows as long as they match the rules.
- BunJS: JavaScript Runtime, faster than NodeJS.
- ElysiaJS: BunJS web framework for API routes and routing.
- Sqlite and Drizzle ORM: Sqlite Database with Drizzle Object–relational mapping built to work best with TypeScript types support for maximum type safety.