hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
182 stars 105 forks source link

[FEAT]: Database Setup and Configuration #236

Closed authcornelius closed 2 weeks ago

authcornelius commented 1 month ago

Description

Database Setup

DB Configuration

Set up a database for the chosen framework’s ORM.

Setup Validation

To validate the setup, you must complete the following steps:

Tables and Constraints

Tables Seeding

Acceptance Criteria

Endpoints

[GET] api/v1/users/user_one_id

Sample Response:

{
  "name": "John Doe",
  "id": "some-user-id",
  "email": "johndoe@example.com",
  "profile": {
    "first_name": "John",
    "last_name": "Doe",
    "phone": "1234567890",
    "avatar_url": "http://example.com/avatar.jpg"
  },
  "organisations": [
    {
      "org_id": "some-org-id-1",
      "name": "Some Org",
      "description": "Some Org Description"
    },
    {
      "org_id": "some-other-org-id-2",
      "name": "Some Other Org",
      "description": "Some Other Org Description"
    }
  ],
  "products": [
    {
      "product_id": "some-product-id",
      "name": "Some Product",
      "description": "Some Product Description"
    },
    {
      "product_id": "some-other-product-id",
      "name": "Some Other Product",
      "description": "Some Other Product Description"
    }
  ]
}

[GET] api/v1/users/user_two_id

Sample Response:

{
  "name": "John Doe",
  "id": "some-user-id",
  "email": "johndoe@example.com",
  "profile": {
    "first_name": "John",
    "last_name": "Doe",
    "phone": "1234567890",
    "avatar_url": "http://example.com/avatar.jpg"
  },
  "organisations": [
    {
      "org_id": "some-org-id-1",
      "name": "Some Org",
      "description": "Some Org Description"
    },
    {
      "org_id": "some-other-org-id-2",
      "name": "Some Other Org",
      "description": "Some Other Org Description"
    },
    {
      "org_id": "some-other-org-id-3",
      "name": "Some Other Org",
      "description": "Some Other Org Description"
    }
  ],
  "products": [
    {
      "product_id": "some-product-id",
      "name": "Some Product",
      "description": "Some Product Description"
    },
    {
      "product_id": "some-other-product-id",
      "name": "Some Other Product",
      "description": "Some Other Product Description"
    }
  ]
}

[POST] api/v1/products

Request Body:

{
  "name": "New Product",
  "description": "Description of the new product"
}

Sample Response:

{
  "status": 201,
  "message": "Product created successfully",
  "product": {
    "product_id": "new-product-id",
    "name": "New Product",
    "description": "Description of the new product"
  }
}

Purpose

This setup ensures that the database is properly configured, validated, and populated with initial data, providing a solid foundation for the application. It also allows users to create new products, saving the product ID in the database.

Requirements

Expected Outcome

Implementation Steps

  1. Clone the boilerplate for your Node.js Express framework.
  2. Create a branch named chore/database-setup from the base branch.
  3. Implement database setup, including migrations, models, and service patterns.
  4. Create and seed the necessary tables.
  5. Implement the endpoints for retrieving user information.
  6. Implement the endpoint for creating a new product.
  7. Ensure proper authentication and authorization for the product creation endpoint.
  8. Validate the setup by ensuring the endpoints work as expected.
sql

This issue now includes the feature where a logged-in user can create a new product, and the product ID is saved in the database.
nedssoft commented 1 month ago

LGTM, go ahead and implement

markessien commented 1 month ago

this is a duplicate