diff --git a/api/src/config/sequelize.config.ts b/api/src/config/sequelize.config.ts index f556095..5e67332 100644 --- a/api/src/config/sequelize.config.ts +++ b/api/src/config/sequelize.config.ts @@ -4,7 +4,7 @@ import env from './environment' const db = new Sequelize(env.DB_DATABASE, env.DB_USERNAME, env.DB_PASSWORD, { host: env.DB_HOST, dialect: 'mariadb', - logging: false + logging: true }) export default db diff --git a/api/src/controllers/taskController.ts b/api/src/controllers/taskController.ts new file mode 100644 index 0000000..6ffb598 --- /dev/null +++ b/api/src/controllers/taskController.ts @@ -0,0 +1,19 @@ +import { Request, Response } from 'express' +import Task from '../models/Task' + +export async function get(req: Request, res: Response) { + try { + const data = await Task.findAll() + res.json(data) + } catch (error) { + res.status(500).send(error) + } +} +export async function add(req: Request, res: Response) { + try { + const task = await Task.create(req.body) + res.json(task) + } catch (error) { + res.status(500).send(error) + } +} diff --git a/api/src/models/Task.ts b/api/src/models/Task.ts new file mode 100644 index 0000000..a8cdca1 --- /dev/null +++ b/api/src/models/Task.ts @@ -0,0 +1,43 @@ +import { DataTypes, Model } from 'sequelize' +import path from 'path' +import db from '../config/sequelize.config' + +class Instance extends Model {} + +Instance.init( + { + _id: { + type: DataTypes.UUID, + defaultValue: DataTypes.UUIDV4, + primaryKey: true, + allowNull: false, + unique: true + }, + title: { + type: DataTypes.STRING, + allowNull: false + }, + client: { + type: DataTypes.STRING, + allowNull: true + }, + project: { + type: DataTypes.STRING, + allowNull: true + }, + timeStart: { + type: DataTypes.BIGINT, + allowNull: false + }, + timeEnd: { + type: DataTypes.BIGINT, + allowNull: true + } + }, + { + sequelize: db, + tableName: path.basename(__filename).split('.')[0].toLowerCase() + } +) + +export default Instance diff --git a/api/src/models/User.ts b/api/src/models/User.ts index 49b8051..4e68815 100644 --- a/api/src/models/User.ts +++ b/api/src/models/User.ts @@ -1,6 +1,6 @@ import { DataTypes, Model } from 'sequelize' import path from 'path' -import db from '../config/sequelize.config.ts' +import db from '../config/sequelize.config' class Instance extends Model {} diff --git a/api/src/routes/apiRoutes.ts b/api/src/routes/apiRoutes.ts new file mode 100644 index 0000000..30d7355 --- /dev/null +++ b/api/src/routes/apiRoutes.ts @@ -0,0 +1,8 @@ +import { Router } from 'express' +import * as taskController from "../controllers/taskController" + +export const router = Router() +//const mws = [handleValidation.handleValidationError] + +router.get("/task/get", taskController.get) +router.post("/task/add", taskController.add) \ No newline at end of file diff --git a/api/src/routes/index.ts b/api/src/routes/index.ts index fec3481..80d5569 100644 --- a/api/src/routes/index.ts +++ b/api/src/routes/index.ts @@ -1,9 +1,11 @@ import { Request, Response, Router } from 'express' import { router as rootRoutes } from './rootRoutes' +import { router as apiRoutes } from './apiRoutes' export const router = Router() router.use(rootRoutes) +router.use("/api/v1", apiRoutes) // 404 router.use((req: Request, res: Response) => { diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 3df0e8d..959ec7c 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -27,6 +27,8 @@ export default { return { username: AppStore.data.user.username } - } + }, + methods: {}, + async created() {} } diff --git a/frontend/src/components/TaskRecord.vue b/frontend/src/components/TaskRecord.vue index 8d75a91..a9419bd 100644 --- a/frontend/src/components/TaskRecord.vue +++ b/frontend/src/components/TaskRecord.vue @@ -29,7 +29,6 @@ const durationInSeconds = computed(() => Math.floor((props.task.timeEnd - props.task.timeStart) / 1000) ) const normalizedDuration = computed(() => formatDuration(durationInSeconds.value)) -console.log(props.task.title)