{"activeVersionTag":"latest","latestAvailableVersionTag":"latest","collection":{"info":{"_postman_id":"00c0689b-beae-4a39-8929-4059abee70ee","name":"scriptorium backend","description":"Author: Kevin Le 1007952805\n\nTo first introduce the context of the app, it is a blog post platform that allows users to share code and run code all in one app. This is the documentation for the backend server of the app.\n\n# Getting Started\n\nIMPORTANT NOTE: - please read the directories of each endpoint section as it will help explain some prerequisites, order of execution for requests etc.\n\n### Pre-reqs:\n\nPlease ensure you have ran the `./startup.sh` to set up a fresh new environment with fresh data and an admin account. After so, run `./run.sh` to start up the backend server to start calling the endpoints.\n\nIf you run into permission issues running the scripts please run the following command: `chmod +x ./startup.sh ./run.sh`\n\n### Admin Account:\n\nBelow is the admin account that should have been generated / created upon running the `./startup.sh` script. Just for reference and whenever needed - but there is already a `login admin` postman request under the `auth directory` that has prefilled the admin data for you to just login as an admin.\n\n- email: [admin@gmail.com](https://mailto:admin@gmail.com)\n    \n- password: 12345\n    \n\n### First Steps:\n\n- [First, the postman collection assumes that the baseUrl is <code>http://localhost:3000</code>](http://localhost:3000) . If it is different, feel free to change the `baseUrl` environment variable of the postman collection to the your baseUrl. Make sure it is the `environment` variables.\n    \n- Next, please head to the live folder to ensure that the app is running. This is just a health check endpoint to ensure that everything is up and running.\n    \n- Next, head over to the auth folder where you can start logging in/ registering new users to initialize postman environment variables that will be propped to the other endpoint folders.\n    \n    - Register the user register user , there is already data there for you to register immediately.\n        \n    - The creds of the user email and passwordwill automatically be passed into the login user postman request\n        \n    - There is also a login admin request that prefills the admin creds to log in with the user.\n        \n    - Important Note: the tokens are set to expire in a 24h window for both access and login\n        \n- This is a good chance to try out the logout request and refresh request features\n    \n\nWith these, now you can navigate to specific directories with more information of the different endpoints. Again, please refer to the respective directory documentation for more information about order of execution and such.\n\nHowever, the order of execution should be top to bottom respective in context of the requests with in the level of the directory.\n\n# Data Models\n\nHere is a database diagram showcasing the database tables and its relation, below will be a brief outline and explanation of each one. Here is the link: [https://dbdiagram.io/d/scriptorium-backend-db-diagram-6727b01fb1b39dd858520245](https://dbdiagram.io/d/scriptorium-backend-db-diagram-6727b01fb1b39dd858520245)\n\n<img src=\"https://content.pstmn.io/24b32aab-0029-4306-a15f-b40210a38ec0/VW50aXRsZWQucG5n\">\n\nHere is a brief skim of the database models that helps orchestrate all the endpoints together.\n\n### 1\\. User\n\nThis is the user table that stores all information relating to the user.\n\n- Fields:\n    \n    - id (Int): Primary key, automatically increments.\n        \n    - email (String): Unique email identifier for each user. (this is encrpyed in db)\n        \n    - password (String): Hashed password for authentication.\n        \n    - firstName (String): User's first name.\n        \n    - lastName (String): User's last name.\n        \n    - avatar (String?): Optional URL to the user's profile image.\n        \n    - phone (String): Contact phone number.\n        \n    - role (String): Role of the user, default is \"user\".\n        \n- Relationships:\n    \n    - codeTemplates (CodeTemplate\\[\\]): Code templates created by the user.\n        \n    - blogs (BlogPost\\[\\]): Blog posts created by the user.\n        \n    - comments (Comment\\[\\]): Comments created by the user.\n        \n    - reports (Report\\[\\]): Reports created by the user.\n        \n    - votes (Vote\\[\\]): Votes cast by the user.\n        \n\n### 2\\. CodeTemplate\n\nThis is a saved code template that a user would have saved or forked.\n\n- Fields:\n    \n    - id (Int): Primary key, automatically increments.\n        \n    - title (String): Title of the code template.\n        \n    - code (String): The code content.\n        \n    - language (String): Programming language of the code.\n        \n    - explanation (String?): Optional explanation or documentation for the code.\n        \n    - userId (Int): Foreign key linking to the user who created the template.\n        \n    - createdAt (DateTime): Timestamp when the template was created.\n        \n    - updatedAt (DateTime): Timestamp when the template was last updated.\n        \n    - parentTemplateId (Int?): Optional ID of the parent template if the code is a fork.\n        \n- Relationships:\n    \n    - user (User): The user who created the template.\n        \n    - tags (CodeTemplateTag\\[\\]): Tags associated with the template.\n        \n    - blogPosts (BlogPostCodeTemplate\\[\\]): Blog posts associated with the template.\n        \n    - forkedTemplates (CodeTemplate\\[\\]): Templates forked from this template.\n        \n\n### 3\\. BlogPost\n\nThis is a blog post by a certain user that can be hidden.\n\n- Fields:\n    \n    - id (Int): Primary key, automatically increments.\n        \n    - title (String): Title of the blog post.\n        \n    - description (String): Short description or excerpt.\n        \n    - content (String): Full content of the blog post.\n        \n    - userId (Int): Foreign key linking to the author.\n        \n    - createdAt (DateTime): Timestamp when the post was created.\n        \n    - updatedAt (DateTime): Timestamp when the post was last updated.\n        \n    - hidden (Boolean): Flag indicating if the post is hidden due to reports or moderation.\n        \n- Relationships:\n    \n    - user (User): The author of the blog post.\n        \n    - tags (BlogPostTag\\[\\]): Tags associated with the blog post.\n        \n    - codeTemplates (BlogPostCodeTemplate\\[\\]): Code templates linked to this post.\n        \n    - comments (Comment\\[\\]): Comments on this post.\n        \n    - votes (Vote\\[\\]): Votes on this post.\n        \n    - report (Report\\[\\]): Reports filed against the post.\n        \n\n### 4\\. BlogPostCodeTemplate (Relationship Table)\n\nTo associate a relationship between blog post and code template, this table is created for blogposts to be able to easily fetch the code templates relating to the blog post (attached within the post)\n\n- Fields:\n    \n    - id (Int): Primary key, automatically increments.\n        \n    - blogPostId (Int): Foreign key linking to the blog post.\n        \n    - codeTemplateId (Int): Foreign key linking to the code template.\n        \n- Relationships:\n    \n    - blogPost (BlogPost): The blog post associated with the template.\n        \n    - codeTemplate (CodeTemplate): The code template associated with the blog post.\n        \n\n### 5\\. Comment\n\nThis table is for commenting. It can either be a comment to a blog post or a comment to another comment (i.e a reply). This can also be hidden as well.\n\n- Fields:\n    \n    - id (Int): Primary key, automatically increments.\n        \n    - content (String): Text content of the comment.\n        \n    - userId (Int): Foreign key linking to the author of the comment.\n        \n    - blogPostId (Int?): Foreign key linking to the blog post, if the comment is on a post.\n        \n    - parentId (Int?): Foreign key linking to the parent comment, if it is a reply.\n        \n    - createdAt (DateTime): Timestamp when the comment was created.\n        \n    - hidden (Boolean): Flag indicating if the comment is hidden due to reports or moderation.\n        \n- Relationships:\n    \n    - user (User): The author of the comment.\n        \n    - blogPost (BlogPost?): The blog post associated with the comment, if applicable.\n        \n    - parent (Comment?): The parent comment if it is a reply.\n        \n    - replies (Comment\\[\\]): Replies to the comment.\n        \n    - votes (Vote\\[\\]): Votes on this comment.\n        \n    - reports (Report\\[\\]): Reports filed against the comment.\n        \n\n### 6\\. Report\n\nThis is a report table that stores all reports for blog posts or comments.\n\n- Fields:\n    \n    - id (Int): Primary key, automatically increments.\n        \n    - reason (String): Reason for reporting the content.\n        \n    - userId (Int): Foreign key linking to the user who reported the content.\n        \n    - blogPostId (Int?): Foreign key linking to the blog post if it was reported.\n        \n    - commentId (Int?): Foreign key linking to the comment if it was reported.\n        \n    - createdAt (DateTime): Timestamp when the report was created.\n        \n- Relationships:\n    \n    - user (User): The user who reported the content.\n        \n    - blogPost (BlogPost?): The blog post being reported, if applicable.\n        \n    - comment (Comment?): The comment being reported, if applicable.\n        \n\n### 7\\. Tag\n\nThis is a generic tag table that stores a unique tag by its name.\n\n- Fields:\n    \n    - id (Int): Primary key, automatically increments.\n        \n    - name (String): Unique name of the tag.\n        \n- Relationships:\n    \n    - codeTags (CodeTemplateTag\\[\\]): Tags associated with code templates.\n        \n    - blogTags (BlogPostTag\\[\\]): Tags associated with blog posts.\n        \n\n### 8\\. CodeTemplateTag (Relationship Table)\n\nUsing the Tag table, this table helps declare a relationship / tag with a code template.\n\n- Fields:\n    \n    - id (Int): Primary key, automatically increments.\n        \n    - codeTemplateId (Int): Foreign key linking to the code template.\n        \n    - tagId (Int): Foreign key linking to the tag.\n        \n- Relationships:\n    \n    - codeTemplate (CodeTemplate): The code template associated with the tag.\n        \n    - tag (Tag): The tag associated with the code template.\n        \n\n### 9\\. BlogPostTag (Relationship Table)\n\nUsing the Tag table, this table helps declare a relationship / tag with a blog post.\n\n- Fields:\n    \n    - id (Int): Primary key, automatically increments.\n        \n    - blogPostId (Int): Foreign key linking to the blog post.\n        \n    - tagId (Int): Foreign key linking to the tag.\n        \n- Relationships:\n    \n    - blogPost (BlogPost): The blog post associated with the tag.\n        \n    - tag (Tag): The tag associated with the blog post.\n        \n\n### 10\\. Vote\n\nThis table stores a certain vote that a user has invoked on a blog post or comment. UP or DOWN.\n\n- Fields:\n    \n    - id (Int): Primary key, automatically increments.\n        \n    - userId (Int): Foreign key linking to the user who cast the vote.\n        \n    - blogPostId (Int?): Foreign key linking to the blog post, if applicable.\n        \n    - commentId (Int?): Foreign key linking to the comment, if applicable.\n        \n    - voteType (String): Type of vote (UP or DOWN).\n        \n- Relationships:\n    \n    - user (User): The user who cast the vote.\n        \n    - blogPost (BlogPost?): The blog post associated with the vote.\n        \n    - comment (Comment?): The comment associated with the vote.\n        \n\n### 11\\. RevokedToken\n\nThis table is used to store all revoked tokens when the user logs out so that they can't use the same token to log back in again or else the backend server will know and decline access the respective endpoint.\n\n- Fields:\n    \n    - id (Int): Primary key, automatically increments.\n        \n    - token (String): Unique identifier for the revoked token.\n        \n    - tokenType (String): Type of token (e.g., \"access\" or \"refresh\").\n        \n\ncreatedAt (DateTime): Timestamp when the token was revoked.","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","isPublicCollection":false,"owner":"30523314","collectionId":"00c0689b-beae-4a39-8929-4059abee70ee","publishedId":"2sAY4x9LpN","public":true,"publicUrl":"https://documenter-api.postman.tech/view/30523314/2sAY4x9LpN","privateUrl":"https://go.postman.co/documentation/30523314-00c0689b-beae-4a39-8929-4059abee70ee","customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"FF6C37"},"documentationLayout":"classic-double-column","customisation":{"metaTags":[{"name":"description","value":"To first introduce the context of the app, it is a blog post platform that allows users to share code and run code all in one app. This is the documentation for the backend server of the app."},{"name":"title","value":""}],"appearance":{"default":"light","themes":[{"name":"dark","logo":null,"colors":{"top-bar":"212121","right-sidebar":"303030","highlight":"FF6C37"}},{"name":"light","logo":null,"colors":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"FF6C37"}}]}},"version":"8.10.1","publishDate":"2024-11-01T09:44:40.000Z","activeVersionTag":"latest","documentationTheme":"light","metaTags":{"title":"","description":"To first introduce the context of the app, it is a blog post platform that allows users to share code and run code all in one app. This is the documentation for the backend server of the app."},"logos":{"logoLight":null,"logoDark":null}},"statusCode":200},"environments":[],"user":{"authenticated":false,"permissions":{"publish":false}},"run":{"button":{"js":"https://run.pstmn.io/button.js","css":"https://run.pstmn.io/button.css"}},"web":"https://www.getpostman.com/","team":{"logo":"https://res.cloudinary.com/postman/image/upload/t_team_logo_pubdoc/v1/team/768118b36f06c94b0306958b980558e6915839447e859fe16906e29d683976f0","favicon":""},"isEnvFetchError":false,"languages":"[{\"key\":\"csharp\",\"label\":\"C#\",\"variant\":\"HttpClient\"},{\"key\":\"csharp\",\"label\":\"C#\",\"variant\":\"RestSharp\"},{\"key\":\"curl\",\"label\":\"cURL\",\"variant\":\"cURL\"},{\"key\":\"dart\",\"label\":\"Dart\",\"variant\":\"http\"},{\"key\":\"go\",\"label\":\"Go\",\"variant\":\"Native\"},{\"key\":\"http\",\"label\":\"HTTP\",\"variant\":\"HTTP\"},{\"key\":\"java\",\"label\":\"Java\",\"variant\":\"OkHttp\"},{\"key\":\"java\",\"label\":\"Java\",\"variant\":\"Unirest\"},{\"key\":\"javascript\",\"label\":\"JavaScript\",\"variant\":\"Fetch\"},{\"key\":\"javascript\",\"label\":\"JavaScript\",\"variant\":\"jQuery\"},{\"key\":\"javascript\",\"label\":\"JavaScript\",\"variant\":\"XHR\"},{\"key\":\"c\",\"label\":\"C\",\"variant\":\"libcurl\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Axios\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Native\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Request\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Unirest\"},{\"key\":\"objective-c\",\"label\":\"Objective-C\",\"variant\":\"NSURLSession\"},{\"key\":\"ocaml\",\"label\":\"OCaml\",\"variant\":\"Cohttp\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"cURL\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"Guzzle\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"HTTP_Request2\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"pecl_http\"},{\"key\":\"powershell\",\"label\":\"PowerShell\",\"variant\":\"RestMethod\"},{\"key\":\"python\",\"label\":\"Python\",\"variant\":\"http.client\"},{\"key\":\"python\",\"label\":\"Python\",\"variant\":\"Requests\"},{\"key\":\"r\",\"label\":\"R\",\"variant\":\"httr\"},{\"key\":\"r\",\"label\":\"R\",\"variant\":\"RCurl\"},{\"key\":\"ruby\",\"label\":\"Ruby\",\"variant\":\"Net::HTTP\"},{\"key\":\"shell\",\"label\":\"Shell\",\"variant\":\"Httpie\"},{\"key\":\"shell\",\"label\":\"Shell\",\"variant\":\"wget\"},{\"key\":\"swift\",\"label\":\"Swift\",\"variant\":\"URLSession\"}]","languageSettings":[{"key":"csharp","label":"C#","variant":"HttpClient"},{"key":"csharp","label":"C#","variant":"RestSharp"},{"key":"curl","label":"cURL","variant":"cURL"},{"key":"dart","label":"Dart","variant":"http"},{"key":"go","label":"Go","variant":"Native"},{"key":"http","label":"HTTP","variant":"HTTP"},{"key":"java","label":"Java","variant":"OkHttp"},{"key":"java","label":"Java","variant":"Unirest"},{"key":"javascript","label":"JavaScript","variant":"Fetch"},{"key":"javascript","label":"JavaScript","variant":"jQuery"},{"key":"javascript","label":"JavaScript","variant":"XHR"},{"key":"c","label":"C","variant":"libcurl"},{"key":"nodejs","label":"NodeJs","variant":"Axios"},{"key":"nodejs","label":"NodeJs","variant":"Native"},{"key":"nodejs","label":"NodeJs","variant":"Request"},{"key":"nodejs","label":"NodeJs","variant":"Unirest"},{"key":"objective-c","label":"Objective-C","variant":"NSURLSession"},{"key":"ocaml","label":"OCaml","variant":"Cohttp"},{"key":"php","label":"PHP","variant":"cURL"},{"key":"php","label":"PHP","variant":"Guzzle"},{"key":"php","label":"PHP","variant":"HTTP_Request2"},{"key":"php","label":"PHP","variant":"pecl_http"},{"key":"powershell","label":"PowerShell","variant":"RestMethod"},{"key":"python","label":"Python","variant":"http.client"},{"key":"python","label":"Python","variant":"Requests"},{"key":"r","label":"R","variant":"httr"},{"key":"r","label":"R","variant":"RCurl"},{"key":"ruby","label":"Ruby","variant":"Net::HTTP"},{"key":"shell","label":"Shell","variant":"Httpie"},{"key":"shell","label":"Shell","variant":"wget"},{"key":"swift","label":"Swift","variant":"URLSession"}],"languageOptions":[{"label":"C# - HttpClient","value":"csharp - HttpClient - C#"},{"label":"C# - RestSharp","value":"csharp - RestSharp - C#"},{"label":"cURL - cURL","value":"curl - cURL - cURL"},{"label":"Dart - http","value":"dart - http - Dart"},{"label":"Go - Native","value":"go - Native - Go"},{"label":"HTTP - HTTP","value":"http - HTTP - HTTP"},{"label":"Java - OkHttp","value":"java - OkHttp - Java"},{"label":"Java - Unirest","value":"java - Unirest - Java"},{"label":"JavaScript - Fetch","value":"javascript - Fetch - JavaScript"},{"label":"JavaScript - jQuery","value":"javascript - jQuery - JavaScript"},{"label":"JavaScript - XHR","value":"javascript - XHR - JavaScript"},{"label":"C - libcurl","value":"c - libcurl - C"},{"label":"NodeJs - Axios","value":"nodejs - Axios - NodeJs"},{"label":"NodeJs - Native","value":"nodejs - Native - NodeJs"},{"label":"NodeJs - Request","value":"nodejs - Request - NodeJs"},{"label":"NodeJs - Unirest","value":"nodejs - Unirest - NodeJs"},{"label":"Objective-C - NSURLSession","value":"objective-c - NSURLSession - Objective-C"},{"label":"OCaml - Cohttp","value":"ocaml - Cohttp - OCaml"},{"label":"PHP - cURL","value":"php - cURL - PHP"},{"label":"PHP - Guzzle","value":"php - Guzzle - PHP"},{"label":"PHP - HTTP_Request2","value":"php - HTTP_Request2 - PHP"},{"label":"PHP - pecl_http","value":"php - pecl_http - PHP"},{"label":"PowerShell - RestMethod","value":"powershell - RestMethod - PowerShell"},{"label":"Python - http.client","value":"python - http.client - Python"},{"label":"Python - Requests","value":"python - Requests - Python"},{"label":"R - httr","value":"r - httr - R"},{"label":"R - RCurl","value":"r - RCurl - R"},{"label":"Ruby - Net::HTTP","value":"ruby - Net::HTTP - Ruby"},{"label":"Shell - Httpie","value":"shell - Httpie - Shell"},{"label":"Shell - wget","value":"shell - wget - Shell"},{"label":"Swift - URLSession","value":"swift - URLSession - Swift"}],"layoutOptions":[{"value":"classic-single-column","label":"Single Column"},{"value":"classic-double-column","label":"Double Column"}],"versionOptions":[],"environmentOptions":[{"value":"0","label":"No Environment"}],"canonicalUrl":"https://documenter.gw.postman.com/view/metadata/2sAY4x9LpN"}