{"id":17794185,"url":"https://github.com/pyk/salestock-backend-ta","last_synced_at":"2025-08-11T00:46:36.496Z","repository":{"id":65492483,"uuid":"50319402","full_name":"pyk/salestock-backend-ta","owner":"pyk","description":"Salestock Backend Technical Assesment","archived":false,"fork":false,"pushed_at":"2016-01-25T19:07:54.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T23:34:11.589Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://salestock-backend-ta.herokuapp.com/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pyk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-25T02:05:46.000Z","updated_at":"2016-02-19T15:44:35.000Z","dependencies_parsed_at":"2023-01-25T19:55:10.320Z","dependency_job_id":null,"html_url":"https://github.com/pyk/salestock-backend-ta","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyk%2Fsalestock-backend-ta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyk%2Fsalestock-backend-ta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyk%2Fsalestock-backend-ta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyk%2Fsalestock-backend-ta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pyk","download_url":"https://codeload.github.com/pyk/salestock-backend-ta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246741315,"owners_count":20826104,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-27T11:15:25.023Z","updated_at":"2025-04-02T02:21:19.859Z","avatar_url":"https://github.com/pyk.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Salestock Backend Technical Assesment\nThis is The Salestock Backend TA. They give me two cases, and I choose the product and category management with hierarchical tree data for category. \n\nThe end goal of this TA is to build API endpoint for that case.\n\n## Model \u0026 Database\nI keep the database schema fairly simple without sacrificing the end goal of this assesment. Since I use `knex` module and `bookshelf` module to manage migrations, seeds data, and model abstraction this API can be easily extended by another nodejs developers.\n\nI use the adjacency list model as a solution to the hierarchical tree data for category. It's very practical and have a good performance, so far.\n\n## API Endpoints\nEach description of endpoint will formatted like the following:\n\n```\n[HTTP METHOD] [ENDPOINT] - [DESCRIPTION]\n```\n\nEach `[ENDPOINT]` is relative to `http://salestock-backend-ta.herokuapp.com`. \n\nSo for example \n\n```\nGET /categories - List of all categories including related sub-category\n```\n\nis translated to `http://salestock-backend-ta.herokuapp.com/categories`.\n\nAlso, there is a `curl(1)` command that I use to play with the endpoint. You can copy \u0026 paste those command to your terminal. You can also use `postman` extension on Google Chrome or similar tool that you are familiar with.\n\n### Categories\nEach category have exactly one sup-category/parent category and many sub-category/childs category.\n\n#### List of categories and the corresponding sub-categories\nThis endpoint is used for displaying all categories and related sub-categories. It can be useful for navigation, dropdown menu of categories for instance.\n\n```\nGET /categories - fetch all categories and their corresponding sub-categories.\n\n# curl(1) test, copy \u0026 paste this on your terminal\ncurl -i -H \"Accept: application/json\" http://salestock-backend-ta.herokuapp.com/categories\n``` \nView in your browser [salestock-backend-ta.herokuapp.com/categories](http://salestock-backend-ta.herokuapp.com/categories).\n\n#### Create a Category\nThis endpoint is used to create new category. The payload of request is a JSON object with `name` and `parent_name` field.\n\n```\nPOST /categories - create a new category\n\n# curl(1) test, copy \u0026 paste this on your terminal\ncurl -i -H \"Content-Type: application/json\" -X POST -d '{\"name\":\"Demo Dress\", \"parent_name\": \"Dress\"}' http://salestock-backend-ta.herokuapp.com/categories\n```\n\nFor the root category, `parent_name` should be empty string. Newly created category will available on list endpoint.\n\n#### Read a Category\nThis endpoint is used to get one category with specified id and related sub-categories. \n\n```\nGET /categories/:id - Request a single category with specified id\n\n# curl(1) test, copy \u0026 paste this on your terminal\ncurl -i -H \"Accept: application/json\" http://salestock-backend-ta.herokuapp.com/categories/1\n```\n\nView example in your browser [salestock-backend-ta.herokuapp.com/categories/1](http://salestock-backend-ta.herokuapp.com/categories/1).\n\n#### Update a Category\nThis endpoint is used to update category. The payload of request is a JSON object with required `name` field.\n\n```\nPUT /categories/:id - Update a category\n\n# curl(1) test, copy \u0026 paste this on your terminal\n# change x with one of category ID\ncurl -i -H \"Content-Type: application/json\" -X PUT -d '{\"name\":\"Update name\"}' http://salestock-backend-ta.herokuapp.com/categories/x\n```\n\n#### Delete a Category\nThis endpoint is used to delete a category. The parent category are cannot deleted until all the sub-categories are deleted.\n\n```\nDELETE /categories/:id - Delete a category\n\n# curl(1) test, copy \u0026 paste this on your terminal\n# change x with one of category ID\ncurl -i -H \"Accept: application/json\" -X DELETE http://salestock-backend-ta.herokuapp.com/categories/x\n```\n\n\n### Products\nEach products have many categories.\n\n#### List of Products\nThis endpoint is used for displaying all products and their categories.\n\n```\nGET /products - Request all products\nGET /products/category/:id - Request all products from a single category\n\n# curl(1) test, copy \u0026 paste this on your terminal\ncurl -i -H \"Accept: application/json\" http://salestock-backend-ta.herokuapp.com/products\n\ncurl -i -H \"Accept: application/json\" http://salestock-backend-ta.herokuapp.com/products/category/13\n``` \n\nView in your browser [salestock-backend-ta.herokuapp.com/products](http://salestock-backend-ta.herokuapp.com/products).\n\n#### Create a Product\nThis endpoint is used to create new product. The payload of request is a JSON object with `name` and `categories` field. `categories` field have value an array of category name for the product.\n\nOnly valid category name will be assigned to a product.\n\n```\nPOST /products - Create new product\n\n# curl(1) test, copy \u0026 paste this on your terminal\ncurl -i -H \"Content-Type: application/json\" -X POST -d '{\"name\":\"Product Demo\", \"categories\": [\"Dress\", \"Long Dress\"]}' http://salestock-backend-ta.herokuapp.com/products\n```\n\n#### Read a Product\nThis endpoint is used to get one product with specified id and related categories.\n\n```\nGET /products/:id - Request a single product with specified id\n\n# curl(1) test, copy \u0026 paste this on your terminal\ncurl -i -H \"Accept: application/json\" http://salestock-backend-ta.herokuapp.com/products/1\n```\n\nView example in your browser [salestock-backend-ta.herokuapp.com/products/1](http://salestock-backend-ta.herokuapp.com/products/1).\n\n#### Update a Product\nThis endpoint is used to update product. The payload of request is a JSON object with required `name` field.\n\n```\nPUT /products/:id - Update a Product\n\n# curl(1) test, copy \u0026 paste this on your terminal\n# change x with one of category ID\ncurl -i -H \"Content-Type: application/json\" -X PUT -d '{\"name\":\"Update name\"}' http://salestock-backend-ta.herokuapp.com/products/x\n```\n\n#### Delete a Product\nThis endpoint is used to delete a product. \n\n```\nDELETE /products/:id - Delete a product\n\n# curl(1) test, copy \u0026 paste this on your terminal\n# change x with one of category ID\ncurl -i -H \"Accept: application/json\" -X DELETE http://salestock-backend-ta.herokuapp.com/categories/x\n```\n\n## License\nBSD 3-clause\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyk%2Fsalestock-backend-ta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyk%2Fsalestock-backend-ta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyk%2Fsalestock-backend-ta/lists"}