Sharkey/packages/backend/src/server/api/endpoints/gallery/featured.ts
syuilo d071d18dd7
refactor: Use ESM (#8358)
* wip

* wip

* fix

* clean up

* Update tsconfig.json

* Update activitypub.ts

* wip
2022-02-27 11:07:39 +09:00

36 lines
860 B
TypeScript

import define from '../../define.js';
import { GalleryPosts } from '@/models/index.js';
export const meta = {
tags: ['gallery'],
requireCredential: false,
res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'GalleryPost',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {},
required: [],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => {
const query = GalleryPosts.createQueryBuilder('post')
.andWhere('post.createdAt > :date', { date: new Date(Date.now() - (1000 * 60 * 60 * 24 * 3)) })
.andWhere('post.likedCount > 0')
.orderBy('post.likedCount', 'DESC');
const posts = await query.take(10).getMany();
return await GalleryPosts.packMany(posts, me);
});