feat: implement activity logging for user actions and create activities table
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 44s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 44s
This commit is contained in:
parent
6c75efbc28
commit
7e2f320b4f
12 changed files with 420 additions and 160 deletions
43
app/controllers/activities_controller.ts
Normal file
43
app/controllers/activities_controller.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// app/controllers/activities_controller.ts
|
||||
import type { HttpContext } from '@adonisjs/core/http';
|
||||
import Activity from '#models/activity';
|
||||
|
||||
export default class ActivitiesController {
|
||||
async index({ response }: HttpContext) {
|
||||
// const activities = await Activity.query()
|
||||
// .preload('user', (q) => q.select('id', 'login'))
|
||||
// .orderBy('created_at', 'desc')
|
||||
// .limit(10);
|
||||
|
||||
// return response.json(
|
||||
// activities.map((a) => ({
|
||||
// id: a.id,
|
||||
// type: a.type,
|
||||
// description: a.description,
|
||||
// user: a.user?.login ?? null,
|
||||
// created_at: a.createdAt.toISO(), // relativeTime() expects ISO
|
||||
// })),
|
||||
// );
|
||||
try {
|
||||
const activities = await Activity.query()
|
||||
.preload('user', (q) => q.select('id', 'login'))
|
||||
.orderBy('created_at', 'desc')
|
||||
.limit(10);
|
||||
|
||||
return response.json(
|
||||
activities.map((a) => ({
|
||||
id: a.id,
|
||||
type: a.type,
|
||||
description: a.description,
|
||||
user: a.user?.login ?? null,
|
||||
created_at: a.createdAt.toISO(), // relativeTime() expects ISO
|
||||
})),
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error fetching activities:', error);
|
||||
return response.status(500).json({ error: 'Internal Server Error' });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue