-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from viniciuscosmome/feature/create-tasks
[LOR 144] feature: create tasks
- Loading branch information
Showing
21 changed files
with
468 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
prisma/migrations/20231030230934_format_lowercases/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Warnings: | ||
- The values [MALE,FEMALE] on the enum `Genders` will be removed. If these variants are still used in the database, this will fail. | ||
- The values [ADMIN,USER] on the enum `Roles` will be removed. If these variants are still used in the database, this will fail. | ||
- The values [ACTIVE,DISABLED,BLOCKED] on the enum `Status` will be removed. If these variants are still used in the database, this will fail. | ||
*/ | ||
-- AlterEnum | ||
BEGIN; | ||
CREATE TYPE "Genders_new" AS ENUM ('male', 'female'); | ||
ALTER TABLE "children_profiles" ALTER COLUMN "gender" TYPE "Genders_new" USING ("gender"::text::"Genders_new"); | ||
ALTER TYPE "Genders" RENAME TO "Genders_old"; | ||
ALTER TYPE "Genders_new" RENAME TO "Genders"; | ||
DROP TYPE "Genders_old"; | ||
COMMIT; | ||
|
||
-- AlterEnum | ||
BEGIN; | ||
CREATE TYPE "Roles_new" AS ENUM ('admin', 'user'); | ||
ALTER TABLE "credentials" ALTER COLUMN "role" DROP DEFAULT; | ||
ALTER TABLE "credentials" ALTER COLUMN "role" TYPE "Roles_new" USING ("role"::text::"Roles_new"); | ||
ALTER TYPE "Roles" RENAME TO "Roles_old"; | ||
ALTER TYPE "Roles_new" RENAME TO "Roles"; | ||
DROP TYPE "Roles_old"; | ||
ALTER TABLE "credentials" ALTER COLUMN "role" SET DEFAULT 'user'; | ||
COMMIT; | ||
|
||
-- AlterEnum | ||
BEGIN; | ||
CREATE TYPE "Status_new" AS ENUM ('active', 'disabled', 'blocked'); | ||
ALTER TABLE "credentials" ALTER COLUMN "status" DROP DEFAULT; | ||
ALTER TABLE "credentials" ALTER COLUMN "status" TYPE "Status_new" USING ("status"::text::"Status_new"); | ||
ALTER TYPE "Status" RENAME TO "Status_old"; | ||
ALTER TYPE "Status_new" RENAME TO "Status"; | ||
DROP TYPE "Status_old"; | ||
ALTER TABLE "credentials" ALTER COLUMN "status" SET DEFAULT 'disabled'; | ||
COMMIT; | ||
|
||
-- AlterTable | ||
ALTER TABLE "credentials" ALTER COLUMN "status" SET DEFAULT 'disabled', | ||
ALTER COLUMN "role" SET DEFAULT 'user'; |
11 changes: 11 additions & 0 deletions
11
prisma/migrations/20231030232151_task_categories/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- CreateEnum | ||
CREATE TYPE "TaskGroup" AS ENUM ('study', 'routine'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "task_categories" ( | ||
"id" TEXT NOT NULL, | ||
"group" "TaskGroup" NOT NULL, | ||
"category" TEXT NOT NULL, | ||
|
||
CONSTRAINT "task_categories_pkey" PRIMARY KEY ("id") | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- CreateEnum | ||
CREATE TYPE "TaskFrequency" AS ENUM ('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "TaskShift" AS ENUM ('morning', 'afternoon', 'night'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "tasks" ( | ||
"id" SERIAL NOT NULL, | ||
"shift" "TaskShift" NOT NULL, | ||
"frequency" "TaskFrequency" NOT NULL, | ||
"order" INTEGER NOT NULL, | ||
"category_id" TEXT NOT NULL, | ||
"children_id" INTEGER NOT NULL, | ||
"updated_at" TIMESTAMP(3) NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "tasks_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "tasks" ADD CONSTRAINT "tasks_category_id_fkey" FOREIGN KEY ("category_id") REFERENCES "task_categories"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "tasks" ADD CONSTRAINT "tasks_children_id_fkey" FOREIGN KEY ("children_id") REFERENCES "children_profiles"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { PrismaClient, TaskCategory } from '@prisma/client'; | ||
|
||
const taskCategories: Array<Partial<TaskCategory>> = [ | ||
{ | ||
id: '44f29121-b7b1-4d1a-bbff-5f1cf2fc5497', | ||
group: 'study', | ||
category: 'school', | ||
}, | ||
{ | ||
id: 'e9f17f88-7c94-4953-a1eb-bce035c483d8', | ||
group: 'study', | ||
category: 'reinforcement', | ||
}, | ||
{ | ||
id: '8c004aa0-961d-4ec4-b6fe-cb70cbc0c4c1', | ||
group: 'study', | ||
category: 'languages', | ||
}, | ||
{ | ||
id: '648d5ce9-6880-476e-bf98-0d7139aadb2c', | ||
group: 'study', | ||
category: 'sport', | ||
}, | ||
{ | ||
id: '549a70f6-3f9c-4640-9b1e-b23d69f1d213', | ||
group: 'study', | ||
category: 'reading', | ||
}, | ||
{ | ||
id: '6166d506-b5f0-4feb-b900-e78d23f1e6ac', | ||
group: 'study', | ||
category: 'musicTherapy', | ||
}, | ||
{ | ||
id: '49f9aed1-e583-427c-82bf-a596513a6707', | ||
group: 'study', | ||
category: 'psychologist', | ||
}, | ||
{ | ||
id: 'aa61d985-93a9-4ee0-b465-2e73848c84a8', | ||
group: 'study', | ||
category: 'speechTherapist', | ||
}, | ||
{ | ||
id: '1b2f2a80-9b3e-455d-aab4-66ba68e6dac0', | ||
group: 'study', | ||
category: 'pedagogue', | ||
}, | ||
{ | ||
id: '7da68252-143d-4e98-b5b0-17c7ea9953a3', | ||
group: 'study', | ||
category: 'occupationalTherapist', | ||
}, | ||
{ | ||
id: '6dfc15bb-f422-4c75-b2cc-bf3e9806c76a', | ||
group: 'routine', | ||
category: 'bathTime', | ||
}, | ||
{ | ||
id: '61123e8a-22af-421f-8e0d-6356c920803b', | ||
group: 'routine', | ||
category: 'brushTeeth', | ||
}, | ||
{ | ||
id: '15d2ceb0-ab06-4cf6-8e46-54ccf8c1e556', | ||
group: 'routine', | ||
category: 'breakfast', | ||
}, | ||
{ | ||
id: '5431e6bf-c1d3-43b6-9289-843ca6455ee3', | ||
group: 'routine', | ||
category: 'lunch', | ||
}, | ||
{ | ||
id: '27e4089a-8643-487d-9634-2332419c2adc', | ||
group: 'routine', | ||
category: 'afternoonLunch', | ||
}, | ||
{ | ||
id: 'a6284261-134d-4c96-ad1c-4afd50ae493d', | ||
group: 'routine', | ||
category: 'dinner', | ||
}, | ||
{ | ||
id: '161bf998-4bf3-4c9f-bd72-1542bad40ed9', | ||
group: 'routine', | ||
category: 'drinkWater', | ||
}, | ||
{ | ||
id: '86008ded-8ba1-4719-a55e-ef6d8d4cb8b1', | ||
group: 'routine', | ||
category: 'playTime', | ||
}, | ||
{ | ||
id: 'bc920d36-d024-481b-9923-3d2d6a478a81', | ||
group: 'routine', | ||
category: 'tvReleased', | ||
}, | ||
{ | ||
id: '63631065-7485-42d1-a9c1-523787954f56', | ||
group: 'routine', | ||
category: 'videoGameReleased', | ||
}, | ||
]; | ||
|
||
export default async (prisma: PrismaClient) => { | ||
for await (const { id, group, category } of taskCategories) { | ||
await prisma.taskCategory.upsert({ | ||
where: { | ||
id, | ||
}, | ||
update: { | ||
group, | ||
category, | ||
}, | ||
create: { | ||
id, | ||
group, | ||
category, | ||
}, | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
import seedCategories from './categories'; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
async function main() { | ||
await seedCategories(prisma); | ||
} | ||
|
||
main() | ||
.then(() => { | ||
console.info('# -------------------- #'); | ||
console.info('# --- SEED SUCCESS --- #'); | ||
console.info('# -------------------- #'); | ||
}) | ||
.catch(async (error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}) | ||
.finally(async () => { | ||
await prisma.$disconnect(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import configModule from 'src/globals/constants'; | ||
|
||
import { AccountModule } from './modules'; | ||
import { AccountModule, TaskModule } from './modules'; | ||
|
||
@Module({ | ||
imports: [configModule, AccountModule], | ||
imports: [configModule, TaskModule, AccountModule], | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.