Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perikk 50 create delete user endpoint #79

Open
wants to merge 121 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
f84b8b1
update .env.example
vherus Jul 11, 2024
1e4a3cd
remove redundant setup doc
vherus Jul 11, 2024
83005bf
update dependencies
vherus Jul 11, 2024
61e4c8d
remove shadow db
vherus Jul 11, 2024
9fa5a68
update migration to fix role conflict type
vherus Jul 11, 2024
2d0ccc2
update migration
vherus Jul 11, 2024
d9f9590
generate api docs
vherus Jul 11, 2024
120fe84
update readme
vherus Jul 11, 2024
1274422
remove old workflow file
vherus Jul 11, 2024
3a80ca5
update readme
vherus Jul 12, 2024
c6f03ec
Implement regex checks and error responses on registration
angustownsley Jul 17, 2024
d544f56
Update documentation
angustownsley Jul 17, 2024
19a19d3
Added placeholder names for post authors
MrStashy Jul 17, 2024
63f4c92
add GET/posts domain created, add GET/posts/id route created
tzoltie Jul 17, 2024
1203a78
Merge pull request #4 from boolean-uk/MrStashy-19-post_author_name_pl…
MrStashy Jul 17, 2024
e3d7be6
added to the entity post, createdAt & updatedAt
homonoviscoding Jul 17, 2024
40eb080
Move validation into its own function
angustownsley Jul 17, 2024
c4c43c1
Create errors file, utilise in validation functions
angustownsley Jul 17, 2024
4bf89db
Merge pull request #3 from boolean-uk/angustownsley-#27-email_and_pas…
angustownsley Jul 17, 2024
aadad81
Profile model update. firstName, lastName, mobile, githubUsername (nu…
MrStashy Jul 17, 2024
c7a5109
Merge pull request #5 from boolean-uk/mama-#26-updated_post_entity
homonoviscoding Jul 17, 2024
bbb0001
merge to main
tzoltie Jul 17, 2024
f661ef0
fixing linting issues
tzoltie Jul 17, 2024
e737f23
Docs updated
MrStashy Jul 17, 2024
cd5f5d7
chore: removed old instructors about generating api docs html
Auenc Jul 17, 2024
4029c55
Merge pull request #7 from boolean-uk/openapi-auto-generate
Auenc Jul 17, 2024
d675650
openapi version turned into a string
MrStashy Jul 17, 2024
f83a827
Merge conflict resolved
MrStashy Jul 17, 2024
d943fbc
Removed redundant commented text from migration.sql
MrStashy Jul 17, 2024
85e918c
updated getAll controller function to return post if user profile doe…
tzoltie Jul 17, 2024
3dbac0b
updated yml file to reflect the updated GET/posts, GET/posts/id contr…
tzoltie Jul 17, 2024
901a3c8
add ability to create teacer -deliveryLog domain and controller
PerikK Jul 17, 2024
74a51a8
merge conflicts resolved
PerikK Jul 17, 2024
2656748
Removed index.html and duplicate docs folder
MrStashy Jul 17, 2024
8797ce1
update api doc link
vherus Jul 18, 2024
343079d
Merge pull request #10 from boolean-uk/vherus-update_api_doc_link
vherus Jul 18, 2024
7144fc3
Merge pull request #8 from boolean-uk/MrStashy-33-restructure_profile…
MrStashy Jul 18, 2024
191f24e
updated yamil file to edit whitespace
tzoltie Jul 18, 2024
75a430a
Update migration to match migration now applied to production
angustownsley Jul 18, 2024
398c686
error res message updated for GET/post/id, yamil file updated
tzoltie Jul 18, 2024
684e1c5
Merge pull request #11 from boolean-uk/angustownsley-36-repair_databa…
angustownsley Jul 18, 2024
3cedb92
add delivery log endpoint
PerikK Jul 18, 2024
51ca9b1
resolve merge conflicts
PerikK Jul 18, 2024
8db7fa0
Refactored auth login controller, updated errors
MrStashy Jul 18, 2024
736139d
add date to the response
PerikK Jul 18, 2024
5969565
Updated docs
MrStashy Jul 18, 2024
69f58b8
fix linting errors
PerikK Jul 18, 2024
2adcf6a
Merge pull request #6 from boolean-uk/backend_team-22-posts_domain
tzoltie Jul 18, 2024
d7b32d8
more linting errors fixed
PerikK Jul 18, 2024
d58b368
Added comma to error object
MrStashy Jul 18, 2024
ca28510
Removed trailing space
MrStashy Jul 18, 2024
0470e36
Merge pull request #13 from boolean-uk/MrStashy-37-Update_auth_contro…
MrStashy Jul 18, 2024
c988113
resolve merge conflicts
PerikK Jul 18, 2024
8738745
more conflicts resolved
PerikK Jul 18, 2024
e3ef63f
small refactoring to satisfy reviews
PerikK Jul 18, 2024
d70ae3d
Ensure profile is created when user is registered
angustownsley Jul 18, 2024
86ef3c3
Merge pull request #14 from boolean-uk/angustownsley-42-user_controll…
angustownsley Jul 18, 2024
19ed128
conforming to boss demands
PerikK Jul 18, 2024
baa01e9
Added validate middleware, error responses
MrStashy Jul 18, 2024
c40da7c
updated PATCH/users/id controller and domain
tzoltie Jul 18, 2024
1eb81bc
conforming to more boss demands
PerikK Jul 18, 2024
14b9c24
merged Will's auth.js file changes with controller and domain changes
tzoltie Jul 18, 2024
2feebc7
Merge pull request #12 from boolean-uk/PerikK_#20_deliveryLog_domain
PerikK Jul 18, 2024
6e461d5
updated merge conflict on utils/errors.js
tzoltie Jul 18, 2024
959b568
update deliveryLog documentation
PerikK Jul 18, 2024
0d561c8
refactored based on review comments
tzoltie Jul 18, 2024
74f302c
Updated controllers/user
MrStashy Jul 18, 2024
16cb33c
defined who can create logs
PerikK Jul 18, 2024
640cdb9
Updated middleware/auth
MrStashy Jul 18, 2024
f448f74
update validateCanPatch function moved to utils/validationFunction, u…
tzoltie Jul 18, 2024
461ed28
Merge pull request #16 from boolean-uk/PerikK_46_update_documentation…
PerikK Jul 18, 2024
c1142c7
Added console log to create (user) function
MrStashy Jul 18, 2024
e00d8e5
update PATCH/users/id - vaildationCanPatch removed from middleware
tzoltie Jul 18, 2024
4da3531
Merge branch 'main' into backend_team-#41-update_patch_users
tzoltie Jul 19, 2024
4cbbdd8
Updated console log message to describe error
MrStashy Jul 19, 2024
9c78560
updated utils/errors.js to resolve merge conflicts
tzoltie Jul 19, 2024
6531a3f
Console log to console error
MrStashy Jul 19, 2024
d7c6791
Updated console.error to display imported error message
MrStashy Jul 19, 2024
e7d411d
resolve merge conflicts
tzoltie Jul 19, 2024
8897dfe
Updated console error log to include both errors
MrStashy Jul 19, 2024
871c8f7
Added 'error' output to console error
MrStashy Jul 19, 2024
99b9d44
refactor based on feedback
tzoltie Jul 19, 2024
d5046bb
Switched error message order
MrStashy Jul 19, 2024
86b97db
validCanPatch function updated, id is taken from logged in user
tzoltie Jul 19, 2024
1cabed2
refactor id is destructured from req.user
tzoltie Jul 19, 2024
4ae9abb
Merge pull request #15 from boolean-uk/backend_team-#41-update_patch_…
tzoltie Jul 19, 2024
bf93078
yamil file updated, PATCH/users/id updated
tzoltie Jul 19, 2024
5cbde8f
yamil file updated, error codes updated for each endpoint
tzoltie Jul 19, 2024
3fa12a6
Merge pull request #21 from boolean-uk/backend_team-#51-update_users_…
tzoltie Jul 19, 2024
acee279
Merge pull request #20 from boolean-uk/MrStashy-45-Update_error_messages
MrStashy Jul 19, 2024
5cc6313
Fix linting errors
angustownsley Jul 19, 2024
c55a262
Added jest, supertest, babel as dev dependencies
MrStashy Jul 19, 2024
48bb7c4
Merge pull request #22 from boolean-uk/angustownsley-53-fix_linting_e…
angustownsley Jul 19, 2024
673eb86
Merge branch 'main' into MrStashy-52-Setup_test_suite_packages
MrStashy Jul 19, 2024
6f22ee8
start delete user endpoint
PerikK Jul 19, 2024
d791069
Merge pull request #23 from boolean-uk/MrStashy-52-Setup_test_suite_p…
MrStashy Jul 19, 2024
57f29b5
update err res body cohort controller
tzoltie Jul 19, 2024
83433e6
update err res body in post controller
tzoltie Jul 19, 2024
7bd1dc0
update err res body in auth controller
tzoltie Jul 19, 2024
3a3df83
merged and resolved conflicts
PerikK Jul 19, 2024
deabdb3
rename validateCanPatch to validateCanModify
PerikK Jul 19, 2024
4ea2e7f
update err res body deliveryLog controller
tzoltie Jul 19, 2024
c67bf01
error file updated to remove redundant code
tzoltie Jul 19, 2024
6258d8c
add and rename some errors
PerikK Jul 19, 2024
6b5c6e4
removed soem duplicate imports in routers result of merge
PerikK Jul 19, 2024
ef8092d
updated users controller linting error
tzoltie Jul 19, 2024
57b0bd3
resolving merge conflicts
tzoltie Jul 19, 2024
c45d0e3
console log added for errors in cohort controller and deliveryLogs co…
tzoltie Jul 19, 2024
c78fbb8
Fix user domain bug preventing cohorts being added
angustownsley Jul 19, 2024
fcb2dde
Merge pull request #24 from boolean-uk/backend_team-##-update_err_res…
tzoltie Jul 19, 2024
f0a93bd
Merge pull request #25 from boolean-uk/angustownsley-56-update_user_d…
angustownsley Jul 19, 2024
65a83d4
Fix patch endpoint bug
angustownsley Jul 19, 2024
a2960ec
Merge pull request #26 from boolean-uk/angustownlsey-61-patch_endpoin…
angustownsley Jul 19, 2024
d38751f
add delete user endpoint
PerikK Jul 19, 2024
263766b
conflicts resolved
PerikK Jul 19, 2024
fcd5cad
linting error fixed
PerikK Jul 19, 2024
8b0ab7a
fixes according the reviews
PerikK Jul 19, 2024
c1798cb
fixes more linting errors
PerikK Jul 19, 2024
dacc54a
fixes more errors according the reviews
PerikK Jul 19, 2024
1e2471c
fixed even more errors according the reviews
PerikK Jul 19, 2024
934967c
minor fixes according to boss review
PerikK Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Dockerfile
.dockerignore
node_modules
.git
.env
5 changes: 0 additions & 5 deletions .env.example

This file was deleted.

4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

18 changes: 0 additions & 18 deletions DB_SETUP.md

This file was deleted.

32 changes: 12 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,28 @@

## Setting up

### Pre-requisite
1. Clone (**do not fork**) the repository
2. `npm ci` to install dependencies
3. Copy `.env.example` to a `.env` file
4. Update the values inside the `.env` file, using your own database connection details. **Do not put the production database details in here, lest you incur the wrath of the gods.**
5. `npm run dev` to run the app
6. Profit

[Follow this guide to create your databases](./DB_SETUP.md)
## Contributing

Once you have complete the above guide, continue to the steps below.

1. Copy `.env.example` and name it `.env` (NOTE: Make sure to copy the file, don't remove the original)
2. Copy the URL of your **PRIMARY** database instance (see image below on how to get this) and place it into the `.env` file's `DATABASE_URL` variable, keeping `?schema=prisma` on the end. E.g. `DATABASE_URL="postgres://uy:[email protected]/ufy?schema=prisma"`
![](./assets/db-setup/4.PNG)
3. Do the same thing for your **SHADOW** database, placing its URL into the `SHADOW_DATABASE_URL` variable, keeping `?schema=shadow` on the end. E.g. `SHADOW_DATABASE_URL="postgres://jk:[email protected]/irk?schema=shadow"`
4. `npm ci` to install dependencies
5. `npx prisma migrate reset` to build the database tables and insert some seed data (as defined in [./prisma/seed.js](./prisma/seed.js))
6. `npm run dev` to run the app
- Project management board: https://github.com/orgs/boolean-uk/projects/13/views/1
- Pull requests MUST be made from branches following the naming convention: `<username>-<issue_number>-<feature>`, e.g. `vherus-#1-user_registration`

## API Spec

[TODO]: <Deploy and update the link below>
[Deployed API Spec](https://UPDATEME)
[Deployed API Spec](https://team-dev-backend-api-nameless-cherry-5503.fly.dev/api-docs/)

The API Spec is hosted by the server itself (i.e. this project), and the view/page is generated automatically by the SwaggerUI libraryi.
The API Spec is hosted by the server itself (i.e. this project), and the view/page is generated automatically by the SwaggerUI library.

To view it locally, you can just go to: [http://localhost:4000/api-docs](http://localhost:4000/api-docs).

Whenever you make any change to the API (e.g. adding a new route, changing the payload for an existing route, adding a new error), you must update the API Spec accordingly. To do this, you just need to update the `openapi.yaml` file -- guidance on the basic structure of the `openapi.yaml` file can be found [here](https://swagger.io/docs/specification/about/).

- **You should always verify these changes locally before committing your work.**
- If your server is already running when you changed the `openapi.yaml` file, you will need to stop and restart your server.
- Once verified, stage and commit the changes on the same branch where you changed the behaviour of the API.

## DATABASE ERD

[TODO]: <Update this with your ERD>
TODO
You must create and include an ERD here. This needs to be kept up to date with any and all database schema changes.
151 changes: 128 additions & 23 deletions docs/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ openapi: 3.0.3
info:
title: Team Dev Server API
description: |-
version: 1.0
version: '1.0'

servers:
- url: http://localhost:4000/
- url: https://team-dev-backend-api-nameless-cherry-5503.fly.dev/
tags:
- name: user
- name: post
Expand All @@ -32,6 +32,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/CreatedUser'
'400':
description: Invalid email/password supplied
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
get:
tags:
- user
Expand All @@ -54,7 +60,7 @@ paths:
schema:
$ref: '#/components/schemas/AllUsers'
'400':
description: fail
description: Incomplete Request
content:
application/json:
schema:
Expand All @@ -69,7 +75,7 @@ paths:
post:
tags:
- user
summary: Localhost Login
summary: Login
description: ''
operationId: loginUser
requestBody:
Expand All @@ -87,7 +93,11 @@ paths:
$ref: '#/components/schemas/loginRes'

'400':
description: Invalid username/password supplied
description: Incomplete Request
content:
application/json:
schema:
$ref: '#/components/schemas/Error'

/users/{id}:
get:
Expand Down Expand Up @@ -118,14 +128,14 @@ paths:
data:
$ref: '#/components/schemas/User'

'400':
description: fail
'500':
description: Unable to get user
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description: fail
description: User not found by that id
content:
application/json:
schema:
Expand All @@ -152,14 +162,26 @@ paths:
schema:
$ref: '#/components/schemas/UpdateUser'
responses:
'201':
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/CreatedUser'
'401':
description: fail
'400':
description: Incomplete Request
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description: A user does not exist with that id
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'403':
description: User is unauthorised to make a change
content:
application/json:
schema:
Expand Down Expand Up @@ -190,7 +212,7 @@ paths:
schema:
$ref: '#/components/schemas/Post'
400:
description: fail
description: Incomplete Request
content:
application/json:
schema:
Expand All @@ -216,17 +238,51 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/posts/{id}:
get:
tags:
- post
summary: Get post by ID
description: get post by id
operationId: getPost
security:
- bearerAuth: []
parameters:
- name: id
in: path
description: ' '
required: true
schema:
type: int
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: object
properties:
status:
type: string
data:
$ref: '#/components/schemas/Posts'
'401':
description: Post not found with that id
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/logs:
post:
tags:
- log
- logs
summary: Create delivery log
description: This can only be done by an authorised teacher user.
operationId: createLog
description: This can only be done by an authorised user with role of TEACHER
operationId: createDeliveryLog
security:
- bearerAuth: []
requestBody:
description: Created log object
description: Create log object
content:
application/json:
schema:
Expand All @@ -250,12 +306,31 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Log'
'401':
400:
description: Incomplete Request
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
401:
description: Unauthorised
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
404:
description: Cohort not found by that id
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
500:
description: An error occured while creating the delivery log
content:
application/json:
schema:
$ref: '#/components/schemas/Error'

/cohorts:
post:
tags:
Expand Down Expand Up @@ -285,6 +360,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
500:
description: Unable to create cohort
content:
application/json:
schema:
$ref: '#/components/schemas/Error'

components:
securitySchemes:
Expand Down Expand Up @@ -349,7 +430,11 @@ components:
type: string
bio:
type: string
githubUrl:
githubUsername:
type: string
username:
type: string
mobile:
type: string

CreateUser:
Expand All @@ -363,10 +448,14 @@ components:
type: string
bio:
type: string
githubUrl:
githubUsername:
type: string
password:
type: string
username:
type: string
mobile:
type: string

UpdateUser:
type: object
Expand All @@ -385,7 +474,11 @@ components:
type: string
bio:
type: string
githubUrl:
githubUsername:
type: string
username:
type: string
mobile:
type: string

Posts:
Expand Down Expand Up @@ -426,10 +519,14 @@ components:
type: string
bio:
type: string
githubUrl:
githubUsername:
type: string
profileImageUrl:
type: string
username:
type: string
mobile:
type: string

CreatedUser:
type: object
Expand All @@ -455,7 +552,11 @@ components:
type: string
bio:
type: string
githubUrl:
githubUsername:
type: string
username:
type: string
mobile:
type: string
login:
type: object
Expand Down Expand Up @@ -490,7 +591,11 @@ components:
type: string
bio:
type: string
githubUrl:
githubUsername:
type: string
username:
type: string
mobile:
type: string
Error:
type: object
Expand Down
Loading
Loading