tiagopazhs / getting-things-done-server

0 stars 0 forks source link

PostgreSQL setup #6

Closed tiagopazhs closed 3 months ago

tiagopazhs commented 3 months ago

goal

expected results

tiagopazhs commented 3 months ago

I used this following command to generate a migration:

npx sequelize-cli model:generate --name ActionTable --attributes name:string,description:string,initialDate:Date,status:string

not necessary to pass id as param, neither created_at and updated_at.

tiagopazhs commented 3 months ago

File to test the model:

import ActionModel from './action.model';

async function testModel() {
    try {
        const newAction = await ActionModel.create({
            name: 'Nome da Ação',
            description: 'Descrição da Ação',
            initialDate: new Date(),
            status: 'ativo'
        });

        console.log('Action created with success:', newAction.toJSON());
    } catch (error) {
        console.error('Error to create the action:', error);
    }
}

testModel();

File to test the task:

import TaskModel from './task.model';

async function testModel() {
    try {
        const newTask = await TaskModel.create({
            name: 'nova',
            status: 'ativo',
            actionId: 3
        });

        console.log('Task created with success:', newTask.toJSON());
    } catch (error) {
        console.error('Error to create the task:', error);
    }
}

testModel();