Implementing the solution for Code Samurai 2022
- Node.js 18+ and npm
Run the following command on your local environment:
git clone https://github.com/BrickedSoft/public_project_planning_codesamurai2022.git my-project-name
cd my-project-name
npm install
-
Input:
- projects.csv: Approved and running project details.
- proposals.csv: Proposed project ideas with estimated cost and times.
- components.csv: Project components, dependencies, completion, and costs.
- agencies.csv: Agency lookup for approval processes.
- constraints.csv: Constraints for evaluating optimal timeframes.
-
Output:
- Build a database system from the provided datasets.
-
Scoring:
- Rewards for successful file parsing, database table design, data filtering, and query API implementation.
-
Define Prisma Models:
- Define models for each entity (projects, proposals, components, agencies, constraints).
-
Initialize Prisma:
- Configure and initialize Prisma to connect to the database.
-
CSV Parsing:
- Use
csv-parser
to read and parse CSV files.
- Use
-
Data Validation and Cleaning:
- Validate and clean CSV data, filtering out invalid or incomplete records.
-
Prisma Client Integration:
- Use Prisma Client to interact with the database.
- Insert records from CSV files into corresponding Prisma models.
-
Query APIs:
- Design and implement query APIs using Prisma Client for data retrieval and updates.
-
Database System:
- Create a database system based on the initial datasets.
Technologies Used:
- Prisma: Object-Relational Mapping (ORM) for database interaction.
- Prisma Client: Auto-generated query builder for type-safe database operations.
- Relational Database: Stores structured data.
- csv-parser: Parses CSV files.
Run the following command on your local environment:
cd public_project_planning_codesamurai2022
npx prisma migrate dev
npm run seed #loads data from csv files to database tables
-
UserType:
- Represents user types with a unique
id
,code
,committee
, anddescription
. - Has a one-to-many relationship with the
User
model.
- Represents user types with a unique
-
Agency:
- Represents agencies with a unique
id
,code
,name
,type
, anddescription
. - Has a one-to-many relationship with the
User
model. - Has a one-to-many relationship with the
ProjectProposal
model.
- Represents agencies with a unique
-
Constraints:
- Represents constraints with a unique
id
,code
,maxLimit
, andconstraintType
.
- Represents constraints with a unique
-
User:
- Represents users with a unique
id
,userTypeId
,agencyId
, and other fields. - Belongs to a
UserType
and anAgency
. - Has a one-to-many relationship with the
ProjectProposal
model.
- Represents users with a unique
-
ProjectProposal:
- Represents project proposals with a unique
id
and various fields. - Belongs to a
User
and anAgency
(executing agency). - Has a one-to-one relationship with the
Project
model. - Has a one-to-many relationship with the
ProjectProposalComponent
model.
- Represents project proposals with a unique
-
Project:
- Represents projects with a unique
id
,projectProposalId
,startDate
,completion
, andactualCost
. - Belongs to a
ProjectProposal
.
- Represents projects with a unique
-
ProjectProposalComponent:
- Represents project proposal components with a unique
id
,projectProposalId
, and other fields. - Belongs to a
ProjectProposal
. - Has a self-referencing relationship ("ParentChild") for ancestor and descendants.
- Represents project proposal components with a unique
The solution employs Prisma, Prisma Client, a relational database, and csv-parser
to build a database system. It includes defining models, initializing Prisma, parsing CSV files, validating data, integrating Prisma Client, designing APIs, and creating a functional database system.
todo
todo
todo
.
├── README.md # README file
├── .github # GitHub folder
├── prisma # Prisma ORM
├── problem_statement
│ └── migrations # db migrations
├── public # Public assets folder
├── app # Next.js
├── libs # libraries
├── package.json # packages
└── tsconfig.json # TypeScript