Bootstrapped based on these instructions.
API documentation available at /docs endpoint
To run the backend in development mode
- install the necessary packages
$ npm install
- create a local MySQL or MariaDB development database
- populate the .env file
#App variables
APP_ENV=DEVELOPEMENT
# APP_ENV=PRODUCTION
# APP_ENV=CI
# only needed when running production
SERVER_IP=
DATABASE_URL=(your database url)
PORT=(port)
ACCESS_TOKEN_SECRET=(your JWT secret)
# Admin user created with seeding script (/src/db/seed.ts)
ADMIN_EMAIL=(your admin email)
ADMIN_PW=(your admin password)- Run the Prisma migrations to add the tables to your development database
$ npx prisma db migrate dev
- Create typescript types for Prisma autogen models (if changes to schema)
$ npx prisma generate
- Run seed script (if not ran automatically when you migrated)
$ npx prisma db seed- build/test and then run the backend in development mode
$ npm run build
$ npm run dev
$ make update_prod
Summary
Get all of the user profiles.
Required Privileges
- Authenticated users
- Admin
Response
application/json
[
{
"name": "Victor Mike",
"profile_img": "",
"email": "victor.mike@app.com",
"id": 10,
"created_at": "2022-11-23T17:23:24.903Z",
"role": {
"name": "Junior DevOps Engineer",
"id": 1
},
"comments": [
{
"content": "Nice idea",
"id": 2,
"updated_at": "2022-11-24T10:36:10.190Z",
"idea": {
"id": 1
}
},
],
"ideas": [
{
"id": 5,
"created_at": "2022-11-29T14:19:22.952Z",
"title": "New idea",
"content": "Some cool idea, must be implemented."
}
],
"likes": [
{
"idea_id": 1
}
]
},
]Summary
Get user profile with specified id.
Required Privileges
- Authenticated users
- Admin
Response
application/json
{
"name": "Victor Mike",
"profile_img": "",
"email": "victor.mike@app.com",
"id": 10,
"created_at": "2022-11-23T17:23:24.903Z",
"role": {
"name": "Junior DevOps Engineer",
"id": 1
},
"comments": [
{
"content": "Nice idea",
"id": 2,
"updated_at": "2022-11-24T10:36:10.190Z",
"idea": {
"id": 1
}
},
],
"ideas": [
{
"id": 5,
"created_at": "2022-11-29T14:19:22.952Z",
"title": "New idea",
"content": "Some cool idea, must be implemented."
}
],
"likes": [
{
"idea_id": 1
}
]
},Summary
Create new user profile.
Required Privileges
- all
Request
multipart/form-data
name: Victor Mike,
role_id: 2,
password: PassWord123,
email: victor.mike@app.com,
avatar: image file
Response
application/json
{
"name": "Victor Mike",
"profile_img": "1669052777822-668015599.jpg",
"email": "victor.mike@app.com",
"id": 10,
"created_at": "2022-11-21T17:46:18.001Z",
"role": {
"name": "Junior DevOps Engineer",
"id": 1
},
"comments": [],
"ideas": [],
"likes": []
}Summary
Update user profile
Required Privileges
- Authenticated users, who are also the target of the update
- Admins
Request
application/json
{
"name": "Micktor Vike",
"email": "micktor.vike@app.com",
"role_id": 8,
"password": "NewPassword123"
}Response
application/json
{
"name": "Micktor Vike",
"profile_img": "1669050855379-231410051.jpg",
"email": "micktor.Vike@app.com",
"id": 2,
"created_at": "2022-11-21T15:02:10.929Z",
"role": {
"name": "Senior DevOps Engineer",
"id":8
},
"ideas": [
{
"id": 5,
"created_at": "2022-11-29T14:19:22.952Z",
"title": "New idea",
"content": "Some cool idea, must be implemented."
}
],
"comments": [
{
"content": "Nice idea",
"id": 2,
"updated_at": "2022-11-24T10:36:10.190Z",
"idea": {
"id": 1
}
},
],
"likes": [
{
"idea_id": 1
}
]
}Summary
Adds image file as specified users avatar.
Required Privileges
- same user as action target
- admin
Request
multipart/form-data
avatar: image file
Response
application/json
{
"name": "Micktor Vike",
"profile_img": "NEW-IMG.jpg",
"email": "micktor.Vike@app.com",
"id": 2,
"created_at": "2022-11-21T15:02:10.929Z",
"role": {
"name": "Senior DevOps Engineer",
"id":8
},
"ideas": [
{
"id": 5,
"created_at": "2022-11-29T14:19:22.952Z",
"title": "New idea",
"content": "Some cool idea, must be implemented."
}
],
"comments": [
{
"content": "Nice idea",
"id": 2,
"updated_at": "2022-11-24T10:36:10.190Z",
"idea": {
"id": 1
}
},
],
"likes": [
{
"idea_id": 1
}
]
}Summary
Deletes profile avatar from specified user, and returns that user.
Required Privileges
- same user as action target
- admin
Response
application/json
{
"name": "Micktor Vike",
"profile_img": "",
"email": "micktor.Vike@app.com",
"id": 2,
"created_at": "2022-11-21T15:02:10.929Z",
"role": {
"name": "Senior DevOps Engineer",
"id":8
},
"ideas": [
{
"id": 5,
"created_at": "2022-11-29T14:19:22.952Z",
"title": "New idea",
"content": "Some cool idea, must be implemented."
}
],
"comments": [
{
"content": "Nice idea",
"id": 2,
"updated_at": "2022-11-24T10:36:10.190Z",
"idea": {
"id": 1
}
},
],
"likes": [
{
"idea_id": 1
}
]
}Summary
Authenticate user with email and password.
Required Privileges
- none
Request
application/json
{
"email": "victor.mike@app.com",
"password": "Password123"
}Response
application/json
{
"name": "Victor Mike",
"profile_img": "",
"email": "victor.mike@app.com",
"id": 10,
"created_at": "2022-11-23T17:23:24.903Z",
"role": {
"name": "Junior DevOps Engineer",
"id": 1
},
"comments": [
{
"content": "Nice idea",
"id": 2,
"updated_at": "2022-11-24T10:36:10.190Z",
"idea": {
"id": 1
}
},
],
"ideas": [
{
"id": 5,
"created_at": "2022-11-29T14:19:22.952Z",
"title": "New idea",
"content": "Some cool idea, must be implemented."
}
],
"likes": [
{
"idea_id": 1
}
],
"token": "JWT_TOKEN_WITH_ID_AND_ROLE_ID"
}Summary
Authenticate user with JWT (Bearer)
Required Privileges
- Authenticated users
- Admin
Response
application/json
{
"name": "Victor Mike",
"profile_img": "",
"email": "victor.mike@app.com",
"id": 10,
"created_at": "2022-11-23T17:23:24.903Z",
"role": {
"name": "Junior DevOps Engineer",
"id": 1
},
"comments": [
{
"content": "Nice idea",
"id": 2,
"updated_at": "2022-11-24T10:36:10.190Z",
"idea": {
"id": 1
}
},
],
"ideas": [
{
"id": 5,
"created_at": "2022-11-29T14:19:22.952Z",
"title": "New idea",
"content": "Some cool idea, must be implemented."
}
],
"likes": [
{
"idea_id": 1
}
],
"token": "JWT_TOKEN_WITH_ID_AND_ROLE_ID"
}Summary
Create new role.
Required privileges
- admin
Request
application/json
{
"name": "Senior Engineer"
}Response
application/json
{
"id": 1,
"name": "Senior Engineer",
"users": []
}Summary
Update role with specifed id.
Required privileges
- admin
Request
application/json
{
"name": "New name for role"
}Response
application/json
{
"id": 1,
"name": "New name for role",
"users": [
{
"name": "Victor Mike",
"id": 10
},
]
}Summary
Get all of the roles.
Required privileges
- authenticated user
- admin
Response
application/json
[
{
"id": 1,
"name": "Senior Developer",
},
{
"id": 2,
"name": "Senior Engineer",
},
]Summary
Get all of the roles, with subscribed users attached to them.
Required privileges
- authenticated user
- admin
Response
application/json
[
{
"id": 1,
"name": "Senior Developer",
"users": [
{
"name": "User 1",
"id": 1
}
]
},
{
"id": 2,
"name": "Senior Engineer",
"users": [
{
"name": "User 2",
"id": 3
}
]
},
]- authenticated user
- admin
Response
application/json
{
"id": 1,
"name": "Senior Developer",
}Summary
Get role with specified id, with all users subscribed to it.
Required privileges
- authenticated user
- admin
Response
application/json
{
"id": 1,
"name": "Senior Developer",
"users": [
{
"name": "User 1",
"id": 1
}
]
}Required privileges
- admin
Response
application/json
{
"id": 1,
"name": "Senior Developer",
},Summary
Get all of the existing ideas.
Querystring
?desc=likes # or comments, or date
?asc=likes # or comments, or date
?page_num=1
?tags=1,2,3
Response
application/json
[
{
"id": 1,
"title": "Add coffee machine",
"content": "We really should have access to free coffee.",
"created_at": "2022-11-23T17:52:40.243Z",
"user": {
"id": 1,
"name": "John Doe"
},
"comments": [
{
"content": "Nice idea",
"user": {
"id": 10,
"name": "Victor Mike"
},
"id": 2,
"created_at": "2022-11-24T10:36:10.190Z"
},
],
"likes": [
{
"user_id": 1
}
],
"tags": [
{
"tag": {
"name": "Cafeteria",
"id": 15
}
},
]
},
]Summary
Get idea with specified id.
Required privileges
- authenticated user
Response
application/json
{
"id": 1,
"title": "Add coffee machine",
"content": "We really should have access to free coffee.",
"created_at": "2022-11-23T17:52:40.243Z",
"user": {
"id": 1,
"name": "John Doe"
},
"comments": [
{
"content": "Nice idea",
"user": {
"id": 10,
"name": "Victor Mike"
},
"id": 2,
"created_at": "2022-11-24T10:36:10.190Z"
},
],
"likes": [
{
"user_id": 1
}
],
"tags": [
{
"tag": {
"name": "Cafeteria",
"id": 15
}
},
]
}Summary
Create new idea. Required Privileges
- authenticated user
- admin
Request
application/json
{
"title": "New idea",
"content": "Some cool idea, must be implemented.",
"tags": [ 1, 17 ]
}Response
application/json
{
"id": 5,
"created_at": "2022-11-29T14:19:22.952Z",
"comments": [],
"user": {
"id": 10,
"name": "Victor Mike"
},
"content": "Some cool idea, must be implemented.",
"likes": [
{
"idea_id": 1
}
],
"title": "New idea",
"tags": [
{
"tag": {
"name": "Management",
"id": 1
}
},
{
"tag": {
"name": "RnD",
"id": 17
}
}
]
}Summary
Update idea with specified id.
Required Privileges
- authenticated owner
- admin
Request
application/json
{
"title": "New idea (Updated)",
"content": "Some cool idea, must be implemented. (Or not)",
"tags": [ 1 ]
}Response
application/json
{
"id": 5,
"user": {
"id": 10,
"name": "Victor Mike"
},
"title": "New idea (Updated)",
"content": "Some cool idea, must be implemented. (Or not)",
"created_at": "2022-11-29T14:19:22.952Z",
"comments": [
{
"content": "Not gonna happen",
"user": {
"id": 1,
"name": "John Doe"
},
"id": 2,
"created_at": "2022-11-24T10:36:10.190Z"
},
],
"likes": [
{
"user_id": 1
}
],
"tags": [
{
"tag": {
"name": "Cafeteria",
"id": 1
}
},
]
}Summary
Remove idea with specified id.
Required Privileges
- authenticated owner
- admin
Response
application/json
{
"id": 5,
"user": {
"id": 10,
"name": "Victor Mike"
},
"title": "New idea (Updated)",
"content": "Some cool idea, must be implemented. (Or not)",
"created_at": "2022-11-29T14:19:22.952Z",
"comments": [
{
"content": "Not gonna happen",
"user": {
"id": 1,
"name": "John Doe"
},
"id": 2,
"created_at": "2022-11-24T10:36:10.190Z"
},
],
"likes": [
{
"user_id": 1
}
],
"tags": [
{
"tag": {
"name": "Cafeteria",
"id": 1
}
},
]
}Summary
Get all of the existing tags.
Required Privileges
- authenticated user
Response
application/json
[
{
"id": 1,
"name": "Food",
"description": "Ideas related to food.",
},
{
"id": 2,
"name": "Management",
"description": "Ideas related to management.",
},
]Summary
Get all of the existing tags, and include users who have subscribed to them.
Required Privileges
- authenticated user
Response
application/json
[
{
"id": 1,
"name": "Food",
"description": "Ideas related to food.",
"users": [
{
"name": "Victor Mike",
"id": 10
}
]
},
{
"id": 2,
"name": "Management",
"description": "Ideas related to management.",
"users": [
{
"name": "John Doe",
"id": 2
},
{
"name": "Victor Mike",
"id": 10
}
]
},
]Summary
Get tag with specified id.
Required Privileges
- authenticated user
Response
application/json
{
"id": 1,
"name": "Food",
"description": "Ideas related to food.",
},Summary
Get tag with specified id. Include users that have subscribed to it. Required Privileges
- authenticated user
Response
application/json
{
"id": 1,
"name": "Food",
"description": "Ideas related to food.",
"users": [
{
"name": "Victor Mike",
"id": 10
}
]
},Summary
Create new tag. Description field is optional.
Required Privileges
- admin
Request
application/json
{
"name": "Snacks",
"description": "Ideas related to snacks served in office"
}{
"name": "Snacks",
}Response
application/json
{
"id": 1,
"name": "Snacks",
"description": "Ideas related to snacks served in office"
}Summary User subscribes to specified tag.
Required Privileges
- authenticated user (same as target)
- admin
Response
application/json
{
"id": 1,
"name": "Snacks",
"description": "Ideas related to snacks served in office",
"users": [
{
"user": {
"name": "Victor Mike",
"id": 10
}
}
]
}Summary
Update tag with specified id.
Required Privileges
- admin
Request
application/json
{
"name": "Snacks V2",
"description": "Ideas related to snacks served in office",
}Response
application/json
{
"id": 2,
"name": "Snacks V2",
"description": "Ideas related to snacks served in office"
}Summary
User unsubscribes from specified tag.
Required Privileges
- authenticated user (same as target)
- admin
Response
application/json
{
"id": 1,
"name": "Snacks",
"description": "Ideas related to snacks served in office",
"users": []
}Summary
Delete specified tag.
Required Privileges
- admin
Response
application/json
{
"id": 1,
"name": "Snacks",
"description": "Ideas related to snacks served in office"
}Summary
Create new comment on idea.
Required Privileges
- Authenticated user.
- admin
Request
application/json
{
"content": "Cool idea :)",
"idea_id": 1
}Response
application/json
{
"content": "Cool idea :)",
"user": {
"id": 10,
"name": "Victor Mike"
},
"id": 2,
"idea": {
"id": 1,
"user_id": 1
},
"created_at": "2022-11-24T10:36:10.190Z"
}Summary
Delete specified Comment.
Required Privileges
- Authenticated user who owns the comment
- admin
Response
application/json
{
"content": "Comment on some idea",
"user": {
"id": 10,
"name": "Victor Mike"
},
"id": 2,
"idea": {
"id": 1,
"user_id": 1
},
"created_at": "2022-11-24T10:36:10.190Z"
}Summary
Update specified Comment.
Required Privileges
- Authenticated user who owns the comment
- admin
Request
application/json
{
"content": "Updated comment content",
}Response
application/json
{
"content": "Updated comment content",
"user": {
"id": 10,
"name": "Victor Mike"
},
"id": 2,
"idea": {
"id": 1,
"user_id": 1
},
"created_at": "2022-11-24T10:36:10.190Z"
}Get all of the comments.
Required Privileges
- Authenticated user
- admin
Response
application/json
[
{
"content": "Nice idea",
"user": {
"id": 10,
"name": "Victor Mike"
},
"id": 2,
"idea": {
"id": 1,
"user_id": 1
},
"created_at": "2022-11-24T10:36:10.190Z"
},
]Summary
Get comment with specified id.
Required Privileges
- Authenticated user
- admin
Response
application/json
{
"content": "Nice idea",
"user": {
"id": 10,
"name": "Victor Mike"
},
"id": 2,
"idea": {
"id": 1,
"user_id": 1
},
"created_at": "2022-11-24T10:36:10.190Z"
},Summary
User likes specified idea.
Required
- Authenticated user
- admin
Response
application/json
{
"user": {
"id": 1,
"name": "admin"
},
"id": 30,
"idea": {
"id": 1,
"user_id": 1
},
"created_at": "2022-11-30T19:01:28.126Z"
}Summary
User removes his/hers like on specified idea.
Required Privileges
- Authenticated user
- admin
Response
application/json
{
"user": {
"id": 10,
"name": "Victor Mike"
},
"id": 30,
"idea": {
"id": 1,
"user_id": 1
},
"created_at": "2022-11-30T19:01:28.126Z"
}Summary
Get all of the likes.
Required Privileges
- admin
Response
application/json
[
{
"user": {
"id": 10,
"name": "Victor Mike"
},
"id": 30,
"idea": {
"id": 1,
"user_id": 1
},
"created_at": "2022-11-30T19:01:28.126Z"
}
]Summary
Get like with specified id
Required Privileges
- admin
Response
application/json
{
"user": {
"id": 10,
"name": "Victor Mike"
},
"id": 30,
"idea": {
"id": 1,
"user_id": 1
},
"created_at": "2022-11-30T19:01:28.126Z"
}Summary
Get all of the likes associated with specified idea. Also includes count of the ideas.
Required Privileges
- Authenticated users
- Admin
Response
application/json
{
"count": 2
"likes": [
{
"id": 1,
"user": {
"id": 10,
"name": "Victor Mike"
}
},
{
"id": 2,
"user": {
"id": 20,
"name": "Bob Mike"
}
}
],
}Summary
Admin can remove any like.
Required Privileges
- admin
Response
application/json
{
"user": {
"id": 10,
"name": "Victor Mike"
},
"id": 30,
"idea": {
"id": 1,
"user_id": 1
},
"created_at": "2022-11-30T19:01:28.126Z"
}