Tables Config
- Configuration is set for each table individually in
tables
object ofdata/appConfig.json
- There are following config options for each table:
readAllConfig
,readByPkConfig
,defaultPagination
, and auth configs:insertAuth
,readAllAuth
,readByPkAuth
,updateAuth
,deleteAuth
. - Explained with an example of the
students
table configuration
Read Configs
Sample Read All Config
{
"readAllConfig": {
"columns": [
"Branch_Id",
"Student_Id",
"Student_Name",
"Course_Id",
"Student_Father",
"college_id"
],
"foreignColumns": {
"Branch_Id": ["Branch_Id", "Branch_Name"],
"Course_Id": ["Course_Id", "Course_Name"],
"college_id": ["college_id", "college_name"]
}
}
}
- The
columns
array specifies the fields to be selected - For the
Branch_Id
foreign key, theBranch_Id
andBranch_Name
columns should be looked up - Similarly for the
Course_Id
andcollege_id
readAllConfig
andreadByPkConfig
are used for the GET all and GET by primary key requests respectively- The
columns
array specifies the fields to be selected from the table - The
foreignColumns
specifies the fields which should be looked up from the foreign table - If foreign table look-up is not required for a particular field, it need not be there in the
foreignColumns
- Hashed fields can't be included
If a field is present in foreignColumns
, it must be present in the columns
to mark it as selected in the first place
Pagination
Sample Pagination
{
"defaultPagination": 20
}
- If no
__limit
query param is provided, at most 20 records will be returned by default
- Used to set the default number of records to be returned in GET all requests if the
__limit
param is not specified - It must be a non-zero positive number, hence pagination is not optional
Auth Configs
- Auth Configs are configurable for each kind of request: GET, POST, PUT and DELETE
- Each auth config contains following fields:
userField
,orgFields
,basicAuth
,allowedRoles
,privileges
andprotectedFields
- These fields are explained below.
User & Org Fields
Sample User & Org Fields
{
"userField": "added_by",
"orgFields": {
"college_id": "college_id",
"Course_Id": "course_id",
"Branch_Id": "branch_id"
},
}
- Here, the value for the
added_by
column will be taken from theusername
in JWT token - For
Course_Id
, the value will be taken from thecourse_id
in JWT token - Similary for
college_id
andBranch_Id
You may want to set the college_id
, Course_Id
, Branch_Id
as foreign keys to the respective colleges
, courses
, branches
table
- These are the fields whose value can be taken from the JWT
access_token
cookie, in all kinds of request - POST, GET, PUT, DELETE - The key in the
orgFields
is the column name in the table and the value is the corresponding column name in the auth table - The value for the
userField
column will be taken fromusername
field from JWT token - The value for the
orgFields
column will be taken from the corresponding field from JWT token
Basic Auth & Allowed Roles
Sample Basic Auth & Allowed Roles
{
"basicAuth": true,
"allowedRoles": ["admin", "principal"]
}
- The
basicAuth
flag, if set, ensures that only logged in users can access the particular resource - The
allowedRoles
restricts the resource to users with the mentioned roles. It can be set only if thebasicAuth
flag is enabled
Privileges & Protected Fields
Sample Privileges & Protected Fields
{
"privileges": {
"Course_Id": ["principal"],
"Branch_Id": ["principal"]
},
"protectedFields": {
"verified": {
"true": ["principal"]
}
}
}
- Here users with
principal
roles should explicitly set the value for theCourse_Id
andBranch_Id
(org) fields - The
true
value for theverified
field can be set by users with theprincipal
role
-
If you want users with some particular roles to explicit set the value of
userField
ororgFields
, useprivileges
to set the config -
For enum-based or boolean columns, you can restrict the users who can set some particular values by using the
protectedFields
object. Its structure is as follows:{
"protectedFields": {
"field1": {
"value1": ["role1", "role2"],
"value2": ["role1"]
},
"field2": {
"value1": ["role1"],
"value2": ["role1", "role2"]
}
}
}tipThe values should be mentioned in strings in the same format as the CSV files
-
It is possible to use
privileges
andprotectedFields
without enablingbasicAuth
. Mention the normal roles as you would, and to address the non-logged-in users, use empty strings""
in the roles array{
"privileges": {
"orgField1": ["role1", ""]
},
"protectedFields": {
"field1": {
"value1": ["role1", ""]
}
}
}
Insert Auth
Sample Insert Auth
{
"insertAuth": {
"userField": "added_by",
"orgFields": ["college_id", "Course_Id", "Branch_Id"],
"basicAuth": true,
"allowedRoles": ["principal", "HoD"],
"privileges": {
"Course_Id": ["principal"],
"Branch_Id": ["principal"]
},
"protectedFields": {
"verified": {
"true": ["principal"]
}
}
}
}
- Values for the
added_by
andcollege_id
fields will be set according to the JWT token for bothprincipal
&HoD
users - Values for
Course_Id
andBranch_Id
are required to be set explicitly by users with theprincipal
role (and set according to token forHoD
users) - Also, only
principal
users can settrue
value for theverified
field
- The
insertAuth
is used to control the behaviour of thePOST
requests - This config, except
basicAuth
andallowedRoles
, is also used inPUT
requests to handle theSET
clause.
Read Auth
Sample Read All Auth
{
"readAllAuth": {
"orgFields": ["college_id", "Course_Id", "Branch_Id"],
"basicAuth": true,
"allowedRoles": ["principal", "HoD", "teacher"],
"privileges": {
"Course_Id": ["principal"],
"Branch_Id": ["principal"]
},
"protectedFields": {
"verified": {
"false": ["principal"]
}
}
}
}
- Value for the
college_id
field will be set according to the JWT token for all ofprincipal
,HoD
&teacher
users - Values for
Course_Id
andBranch_Id
can be set explicitly by users with theprincipal
role (and set according to token forHoD
&teacher
users) - Also, only
principal
users can setfalse
value for theverified
field, meaning only they can access unverified students
- The
readAllAuth
andreadByPkAuth
are used to control the behaviour of theGET
all andGET
by primary key requests respectively
Update Auth
Sample Update Auth
{
"deleteAuth": {
"orgFields": ["college_id", "Course_Id", "Branch_Id"],
"basicAuth": true,
"allowedRoles": ["principal", "HoD"],
"privileges": {
"Course_Id": ["principal"],
"Branch_Id": ["principal"]
}
}
}
- Value for the
college_id
field will be set according to the JWT token for all ofprincipal
&HoD
users - Values for
Course_Id
andBranch_Id
can be set explicitly by users with theprincipal
role (and set according to token forHoD
users)
- The
updateAuth
is used to control theWHERE
clause inPUT
requests - In the given example, users with the
principal
role can update any student of his college, but HoDs can update students only of his department - Just to reiterate, the
insertAuth
config applies in theSET
clause here. For instance, users with onlyprincipal
role can set thetrue
value for theverified
field as mentioned in theinsertAuth
Delete Auth
Sample Delete Auth
{
"deleteAuth": {
"orgFields": ["college_id", "Course_Id", "Branch_Id"],
"basicAuth": true,
"allowedRoles": ["principal", "HoD"],
"privileges": {
"Course_Id": ["principal"],
"Branch_Id": ["principal"]
}
}
}
- Value for the
college_id
field will be set according to the JWT token for all ofprincipal
&HoD
users - Values for
Course_Id
andBranch_Id
can be set explicitly by users with theprincipal
role (and set according to token forHoD
users)
- The
deleteAuth
is used to control theWHERE
clause inDELETE
requests - In the given example, users with the
principal
role can delete any student of his college, but HoDs can delete students only of his department