Skip to content

Commit

Permalink
Merge pull request #61 from RoutinelyOrganization/develop
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
viniciuscosmome authored Nov 30, 2023
2 parents 13b0299 + 32407b8 commit 3a11b88
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 79 deletions.
21 changes: 21 additions & 0 deletions prisma/migrations/20231121180353_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Warnings:
- The values [personal,study,finance,career,health] on the enum `TaskTags` will be removed. If these variants are still used in the database, this will fail.
- Added the required column `category` to the `tasks` table without a default value. This is not possible if the table is not empty.
*/
-- CreateEnum
CREATE TYPE "TaskCategories" AS ENUM ('personal', 'study', 'finance', 'career', 'health');

-- AlterEnum
BEGIN;
CREATE TYPE "TaskTags_new" AS ENUM ('application', 'account', 'excercise', 'beauty', 'literature');
ALTER TABLE "tasks" ALTER COLUMN "tag" TYPE "TaskTags_new" USING ("tag"::text::"TaskTags_new");
ALTER TYPE "TaskTags" RENAME TO "TaskTags_old";
ALTER TYPE "TaskTags_new" RENAME TO "TaskTags";
DROP TYPE "TaskTags_old";
COMMIT;

-- AlterTable
ALTER TABLE "tasks" ADD COLUMN "category" "TaskCategories" NOT NULL;
123 changes: 62 additions & 61 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -11,95 +11,88 @@ datasource db {
}

model Account {
id String @id @default(uuid())
email String @unique
password String
permissions String[]
verifiedAt DateTime? @map("verified_at")
acceptedAt DateTime @default(now()) @map("accepted_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
sessions Session[]
profile Profile?
id String @id @default(uuid())
email String @unique
password String
permissions String[]
verifiedAt DateTime? @map("verified_at")
acceptedAt DateTime @default(now()) @map("accepted_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
sessions Session[]
profile Profile?
resetPasswordToken ResetPasswordToken?
tasks Task[]
goals Goals[]
tasks Task[]
goals Goals[]
@@map("accounts")
}

model ResetPasswordToken {
id Int @id @default(autoincrement())
token String @unique
account Account? @relation(fields: [accountId], references: [id], onDelete: Cascade)
accountId String @unique @map("account_id")
id Int @id @default(autoincrement())
token String @unique
account Account? @relation(fields: [accountId], references: [id], onDelete: Cascade)
accountId String @unique @map("account_id")
createdAt DateTime @default(now()) @map("created_at")
}

model Profile {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
accountId String @unique @map("account_id")
account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
accountId String @unique @map("account_id")
account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
@@map("profiles")
}

model Session {
id Int @id @default(autoincrement())
sessionToken String @unique @map("session_token")
refreshToken String @unique @map("refresh_token")
accountId String @map("account_id")
name String
permissions String[]
remember Boolean @default(false)
sessionExpiresIn DateTime @map("session_expires_in")
refreshExpiresIn DateTime @map("refresh_expires_in")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
id Int @id @default(autoincrement())
sessionToken String @unique @map("session_token")
refreshToken String @unique @map("refresh_token")
accountId String @map("account_id")
name String
permissions String[]
remember Boolean @default(false)
sessionExpiresIn DateTime @map("session_expires_in")
refreshExpiresIn DateTime @map("refresh_expires_in")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
@@map("sessions")
}

model Task {
id Int @id @default(autoincrement())
name String
hour DateTime @db.Time()
date DateTime @db.Date
id Int @id @default(autoincrement())
name String
hour DateTime @db.Time()
date DateTime @db.Date
description String
priority TaskPriorities
tag TaskTags
accountId String @map("account_id")
account Account @relation(fields: [accountId], references: [id])
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
priority TaskPriorities
tag TaskTags
category TaskCategories
accountId String @map("account_id")
account Account @relation(fields: [accountId], references: [id])
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("tasks")
}

model Goals {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
description String
goal String
start_date DateTime @db.Date
end_date DateTime @db.Date
goal String
start_date DateTime @db.Date
end_date DateTime @db.Date
periodicity GoalPeriodicity
type GoalType
accountId String @map("account_id")
account Account @relation(fields: [accountId], references: [id])
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
type GoalType
accountId String @map("account_id")
account Account @relation(fields: [accountId], references: [id])
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("goals")
}
Expand All @@ -125,9 +118,17 @@ enum TaskPriorities {
}

enum TaskTags {
application
account
excercise
beauty
literature
}

enum TaskCategories {
personal
study
finance
career
health
}
}
25 changes: 9 additions & 16 deletions src/modules/Task/task.dtos.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import { ApiProperty, PickType } from '@nestjs/swagger';
import { IsDateString, IsEnum, IsNotEmpty, IsString } from 'class-validator';

export enum TaskPriorities {
low = 'low',
medium = 'medium',
high = 'high',
urgent = 'urgent',
}

export enum TaskTags {
personal = 'personal',
study = 'study',
finance = 'finance',
career = 'career',
health = 'health',
}
import { TaskPriorities, TaskTags, TaskCategories } from '@prisma/client';

export class CreateTaskInput {
@ApiProperty()
Expand Down Expand Up @@ -45,11 +31,17 @@ export class CreateTaskInput {
@IsEnum(TaskPriorities)
priority: TaskPriorities;

@ApiProperty({ enum: TaskTags, example: 'personal' })
@ApiProperty({ enum: TaskTags, example: TaskTags['literature'] })
@IsNotEmpty()
@IsString()
@IsEnum(TaskTags)
tag: TaskTags;

@ApiProperty({ enum: TaskCategories, example: TaskCategories['personal'] })
@IsNotEmpty()
@IsString()
@IsEnum(TaskCategories)
category: TaskCategories;
}

export class UpdateTaskInput extends PickType(CreateTaskInput, [
Expand All @@ -60,6 +52,7 @@ export class UpdateTaskInput extends PickType(CreateTaskInput, [
'name',
'priority',
'tag',
'category',
]) {}

export class FindTasksRepositoryInput {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/Task/task.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class TaskRepository {
name: createTaskInput.name,
priority: createTaskInput.priority,
tag: createTaskInput.tag,
category: createTaskInput.category,
accountId: createTaskInput.accountId,
},
});
Expand Down Expand Up @@ -59,6 +60,7 @@ export class TaskRepository {
hour: true,
tag: true,
priority: true,
category: true,
description: true,
},
});
Expand Down
5 changes: 3 additions & 2 deletions src/modules/Task/tests/stubs/task.stubs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CreateTaskInput } from '../../task.dtos';
import { faker } from '@faker-js/faker';
import { TaskPriorities, TaskTags } from '../../task.dtos';
import { TaskPriorities, TaskTags, TaskCategories } from '@prisma/client';

const datetime = faker.date.recent().toISOString().split('T');

Expand All @@ -10,6 +10,7 @@ export const createTaskInput: CreateTaskInput = {
hour: new Date(datetime[1]),
description: faker.lorem.paragraph(),
priority: TaskPriorities.low,
tag: TaskTags.finance,
tag: TaskTags.account,
category: TaskCategories.finance,
accountId: faker.string.uuid(),
};

0 comments on commit 3a11b88

Please sign in to comment.