Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ Thumbs.db
# Environment file
*.env
*.env.*
!example.env
23 changes: 3 additions & 20 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,11 @@ import { TypeOrmModule } from '@nestjs/typeorm';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UsersModule } from './users/users.module';
import { AuthModule } from './auth/auth.module';
import { PluralNamingStrategy } from './strategies/plural-naming.strategy';
import { TaskModule } from './task/task.module';
import AppDataSource from './data-source';

@Module({
imports: [
TypeOrmModule.forRoot({
type: 'mongodb',
host: '127.0.0.1',
port: 27017,
database: 'c4cOpsTest',
// username: 'root',
// password: 'root',
autoLoadEntities: true,
// entities: [join(__dirname, '**/**.entity.{ts,js}')],
// Setting synchronize: true shouldn't be used in production - otherwise you can lose production data
synchronize: true,
namingStrategy: new PluralNamingStrategy(),
}),
UsersModule,
AuthModule,
],
imports: [TypeOrmModule.forRoot(AppDataSource.options), TaskModule],
controllers: [AppController],
providers: [AppService],
})
Expand Down
22 changes: 22 additions & 0 deletions apps/backend/src/data-source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { DataSource } from 'typeorm';
import { PluralNamingStrategy } from './strategies/plural-naming.strategy';
import { Task } from './task/types/task.entity';
import * as dotenv from 'dotenv';

dotenv.config();

const AppDataSource = new DataSource({
type: 'postgres',
host: process.env.NX_DB_HOST,
port: parseInt(process.env.NX_DB_PORT as string, 10),
username: process.env.NX_DB_USERNAME,
password: process.env.NX_DB_PASSWORD,
database: process.env.NX_DB_DATABASE,
entities: [Task],
migrations: ['apps/backend/src/migrations/*.js'],
// Setting synchronize: true shouldn't be used in production - otherwise you can lose production data
synchronize: false,
namingStrategy: new PluralNamingStrategy(),
});

export default AppDataSource;
19 changes: 19 additions & 0 deletions apps/backend/src/migrations/1754254886189-add_task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddTask1754254886189 implements MigrationInterface {
name = 'AddTask1754254886189';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."tasks_category_enum" AS ENUM('Draft', 'To Do', 'In Progress', 'Completed')`,
);
await queryRunner.query(
`CREATE TABLE "task" ("id" SERIAL NOT NULL, "title" character varying NOT NULL, "description" character varying, "dateCreated" TIMESTAMP NOT NULL DEFAULT now(), "dueDate" TIMESTAMP, "labels" jsonb NOT NULL DEFAULT '[]', "category" "public"."tasks_category_enum" NOT NULL DEFAULT 'Draft', CONSTRAINT "PK_8d12ff38fcc62aaba2cab748772" PRIMARY KEY ("id"))`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "task"`);
await queryRunner.query(`DROP TYPE "public"."tasks_category_enum"`);
}
}
19 changes: 19 additions & 0 deletions apps/backend/src/task/task.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
Query,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { TasksService } from './task.service';
import { Task } from './types/task.entity';

@ApiTags('tasks')
@Controller('tasks')
export class TasksController {
constructor(private readonly tasksService: TasksService) {}
}
13 changes: 13 additions & 0 deletions apps/backend/src/task/task.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TasksController } from './task.controller';
import { TasksService } from './task.service';
import { Task } from './types/task.entity';

@Module({
imports: [TypeOrmModule.forFeature([Task])],
controllers: [TasksController],
providers: [TasksService],
exports: [TasksService],
})
export class TaskModule {}
12 changes: 12 additions & 0 deletions apps/backend/src/task/task.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Task } from './types/task.entity';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';

@Injectable()
export class TasksService {
constructor(
@InjectRepository(Task)
private readonly taskRepository: Repository<Task>,
) {}
}
20 changes: 20 additions & 0 deletions apps/backend/src/task/types/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export enum TaskCategory {
DRAFT = 'Draft',
TODO = 'To Do',
IN_PROGRESS = 'In Progress',
COMPLETED = 'Completed',
}

export const CATEGORY_DESCRIPTIONS: Record<TaskCategory, string> = {
[TaskCategory.DRAFT]: 'Tasks that are still being planned or outlined',
[TaskCategory.TODO]: 'Tasks that are ready to be worked on',
[TaskCategory.IN_PROGRESS]: 'Tasks that are currently being worked on',
[TaskCategory.COMPLETED]: 'Tasks that have been finished',
};

export const CATEGORY_COLORS: Record<TaskCategory, string> = {
[TaskCategory.DRAFT]: '#6B7280', // Gray
[TaskCategory.TODO]: '#3B82F6', // Blue
[TaskCategory.IN_PROGRESS]: '#F59E0B', // Orange
[TaskCategory.COMPLETED]: '#10B981', // Green
};
41 changes: 41 additions & 0 deletions apps/backend/src/task/types/task.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
} from 'typeorm';
import { TaskCategory } from './category'; // Adjust path as needed

export interface Label {
id: string;
name: string;
color?: string;
}

@Entity('tasks')
export class Task {
@PrimaryGeneratedColumn()
id: number;

@Column()
title: string;

@Column({ nullable: true })
description: string;

@CreateDateColumn()
dateCreated: Date;

@Column({ nullable: true })
dueDate?: Date;

@Column('jsonb', { default: () => "'[]'" })
labels: Label[];

@Column({
type: 'enum',
enum: TaskCategory,
default: TaskCategory.DRAFT,
})
category: TaskCategory;
}
5 changes: 5 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NX_DB_HOST=localhost,
NX_DB_USERNAME=postgres,
NX_DB_PASSWORD=,
NX_DB_DATABASE=jumpstart,
NX_DB_PORT=5432,
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
"lint": "eslint apps/frontend --ext .ts,.tsx --fix && eslint apps/backend --ext .ts,.tsx --fix",
"prepush": "yarn run format:check && yarn run lint:check",
"prepush:fix": "yarn run format && yarn run lint",
"prepare": "husky install"
"prepare": "husky install",
"typeorm": "ts-node -r tsconfig-paths/register --project apps/backend/tsconfig.app.json ./node_modules/typeorm/cli.js",
"migration:generate": "npm run typeorm -- migration:generate apps/backend/src/migrations/$npm_config_name -d apps/backend/src/data-source.ts",
"migration:run": "npm run typeorm -- migration:run -d apps/backend/src/data-source.ts",
"migration:revert": "npm run typeorm -- migration:revert -d apps/backend/src/data-source.ts",
"migration:create": "npm run typeorm -- migration:create apps/backend/src/migrations/$npm_config_name"
},
"private": true,
"dependencies": {
Expand All @@ -21,21 +26,23 @@
"@nestjs/platform-express": "^10.0.2",
"@nestjs/swagger": "^7.1.12",
"@nestjs/typeorm": "^10.0.0",
"@types/mongodb": "^4.0.7",
"@types/pg": "^8.15.5",
"amazon-cognito-identity-js": "^6.3.5",
"axios": "^1.5.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"global": "^4.4.0",
"jwks-rsa": "^3.1.0",
"mongodb": "^6.1.0",
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
"pg": "^8.16.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.0",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typeorm": "^0.3.17"
},
"devDependencies": {
Expand Down
Loading
Loading