diff --git a/server/src/migrations/0000_initial.ts b/server/src/migrations/0000_initial.ts index 83bbfe6701f6aaa1bc79a7d4c3d0d8f6520c08d8..e82f541d7010e01830c5864f55bc403cfe44112a 100644 --- a/server/src/migrations/0000_initial.ts +++ b/server/src/migrations/0000_initial.ts @@ -47,8 +47,8 @@ export async function up(database: Knex): Promise<void> { table.string('icon').notNullable(); table.enum('status', [ 'open', 'closed', 'suspended' ]).notNullable(); table.enum('priority', [ 'low', 'medium', 'high', 'urgent' ]).notNullable(); - table.timestamp('created').notNullable(); - table.timestamp('edited').notNullable(); + table.bigInteger('created').notNullable(); + table.bigInteger('edited').notNullable(); }) .createTable('task_dependencies', table => { table.uuid('task_id').notNullable().references('tasks.id'); @@ -73,15 +73,15 @@ export async function up(database: Knex): Promise<void> { table.uuid('task_id').notNullable().references('tasks.id'); table.uuid('user_id').notNullable().references('users.id'); table.text('text').notNullable(); - table.timestamp('created').notNullable(); - table.timestamp('edited').notNullable(); + table.bigInteger('created').notNullable(); + table.bigInteger('edited').notNullable(); }) .createTable('workhours', table => { table.uuid('id').notNullable().primary(); table.uuid('user_id').notNullable().references('users.id'); table.uuid('task_id').notNullable().references('tasks.id'); - table.timestamp('started').notNullable(); - table.timestamp('finished'); + table.bigInteger('started').notNullable(); + table.bigInteger('finished'); }); } diff --git a/server/src/v1/project.ts b/server/src/v1/project.ts index b285bcbf2b56620b90fefa930b6209750e95e7f0..443e725fab53f40b4e1c9e1d26c3bc1fc6dcba06 100644 --- a/server/src/v1/project.ts +++ b/server/src/v1/project.ts @@ -245,18 +245,20 @@ project.get('/:uuid/activity', async (req, res) => { 'team_projects.project_id': id, }) .andWhereNot({ 'workhours.finished': null }) - .andWhere('workhours.started', '>=', since.getTime()) - .andWhere('workhours.started', '<=', to.getTime()) + .andWhereBetween('workhours.started', [since.getTime(), to.getTime()]) .groupBy('workhours.id') ) .select({ - day: database.raw('Date(`started` / 1000, \'unixepoch\')'), // TODO: does not work in prostgres + day: database.raw('`started` / 1000 / 60 / 60 / 24'), }) .sum({ time: database.raw('`finished` - `started`') }) .groupBy('day'); res.status(200).json({ status: 'success', - activity: activity, + activity: activity.map((act: any) => ({ + ...act, + day: (new Date(act.day * 24 * 60 * 60 * 1000)).toISOString().substring(0, 10), + })), }); } else { res.status(400).json({ @@ -278,7 +280,7 @@ project.get('/:uuid/completion', async (req, res) => { if (validate(id)) { const since = new Date(parseInt(req.query.since as string ?? 0)); const to = new Date(parseInt(req.query.to as string ?? Date.now())); - const completion = await database( + const completion: any[] = await database( database('team_members') .innerJoin('team_projects', 'team_members.team_id', 'team_projects.team_id') .innerJoin('tasks', 'team_projects.project_id', 'tasks.project_id') @@ -306,7 +308,7 @@ project.get('/:uuid/completion', async (req, res) => { status: 'status', }) .count({ count: 'id' }) - .groupBy('status') as any[]; + .groupBy('status'); res.status(200).json({ status: 'success', completion: completion.reduce((object, { status, count }) => ({ diff --git a/server/src/v1/team.ts b/server/src/v1/team.ts index 3257771e7cc48b2f3dda2fbe9318601d6b4ae3a9..f86814dc9e22c7e1eb8a5e5be28e826751fc5ade 100644 --- a/server/src/v1/team.ts +++ b/server/src/v1/team.ts @@ -361,7 +361,7 @@ team.get('/:uuid/activity', async (req, res) => { .innerJoin('team_members', 'ut.team_id', 'team_members.team_id') .innerJoin('workhours', 'team_members.user_id', 'workhours.user_id') .select({ - day: database.raw('Date(`workhours`.`started` / 1000, \'unixepoch\')'), // TODO: does not work in postgres + day: database.raw('`started` / 1000 / 60 / 60 / 24'), }) .sum({ time: database.raw('`workhours`.`finished` - `workhours`.`started`') }) .where({ @@ -369,12 +369,14 @@ team.get('/:uuid/activity', async (req, res) => { 'ut.team_id': id, }) .andWhereNot({ 'workhours.finished': null }) - .andWhere('workhours.started', '>=', since.getTime()) - .andWhere('workhours.started', '<=', to.getTime()) + .andWhereBetween('workhours.started', [since.getTime(), to.getTime()]) .groupBy('day'); res.status(200).json({ status: 'success', - activity: activity, + activity: activity.map((act: any) => ({ + ...act, + day: (new Date(act.day * 24 * 60 * 60 * 1000)).toISOString().substring(0, 10), + })), }); } else { res.status(400).json({ diff --git a/server/src/v1/user.ts b/server/src/v1/user.ts index 049646452834c86fef3317ea0a916ecfcda20004..15e04eade4c12ae9a10cbd58a9cd05d0de986653 100644 --- a/server/src/v1/user.ts +++ b/server/src/v1/user.ts @@ -193,21 +193,24 @@ user.get('/activity', async (req, res) => { const to = new Date(parseInt(req.query.to as string ?? Date.now())); const activity = await database('workhours') .select({ - day: database.raw('Date(`started` / 1000, \'unixepoch\')'), // TODO: This does not work in postgres + day: database.raw('`started` / 1000 / 60 / 60 / 24'), }) .sum({ time: database.raw('`finished` - `started`') }) .where({ 'workhours.user_id': req.body.token.id, }) .andWhereNot({ 'workhours.finished': null }) - .andWhere('workhours.started', '>=', since.getTime()) - .andWhere('workhours.started', '<=', to.getTime()) + .andWhereBetween('workhours.started', [since.getTime(), to.getTime()]) .groupBy('day'); res.status(200).json({ status: 'success', - activity: activity, + activity: activity.map((act: any) => ({ + ...act, + day: (new Date(act.day * 24 * 60 * 60 * 1000)).toISOString().substring(0, 10), + })), }); } catch (e) { + console.log(e); res.status(400).json({ status: 'error', message: 'failed get activity',