39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { DatabaseService } from '../database/database.service';
|
|
import type { PageInput } from '../identity/identity.schemas';
|
|
import {
|
|
publicForumSelect,
|
|
publicForumWhere,
|
|
requirePublicThread,
|
|
} from './forum-view';
|
|
@Injectable()
|
|
export class ForumPublicStore {
|
|
constructor(private readonly db: DatabaseService) {}
|
|
list(organizationId: string, page: PageInput) {
|
|
return this.db.forumPost.findMany({
|
|
where: { ...publicForumWhere(organizationId), threadId: null },
|
|
select: publicForumSelect,
|
|
orderBy: [{ createdAt: 'desc' }, { id: 'desc' }],
|
|
skip: page.offset,
|
|
take: page.limit,
|
|
});
|
|
}
|
|
get(organizationId: string, id: string) {
|
|
return requirePublicThread(this.db, organizationId, id);
|
|
}
|
|
async replies(organizationId: string, id: string, page: PageInput) {
|
|
await requirePublicThread(this.db, organizationId, id);
|
|
return this.db.forumPost.findMany({
|
|
where: {
|
|
...publicForumWhere(organizationId),
|
|
threadId: id,
|
|
thread: { ...publicForumWhere(organizationId), threadId: null },
|
|
},
|
|
select: publicForumSelect,
|
|
orderBy: [{ createdAt: 'asc' }, { id: 'asc' }],
|
|
skip: page.offset,
|
|
take: page.limit,
|
|
});
|
|
}
|
|
}
|