All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 44s
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
// 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' });
|
|
}
|
|
}
|
|
|
|
|
|
}
|