You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.8 KiB

import {Controller, view, Injectable, SecurityContext, Inject, Collection} from '@extollo/lib'
import {WorkItem} from '../../models/WorkItem.model'
import {FeedPost} from '../../models/FeedPost.model'
@Injectable()
export class Home extends Controller {
@Inject()
protected readonly security!: SecurityContext
public async welcome() {
const workItems = await this.getWorkItems()
const feedPosts = await this.getFeedPosts()
return view('welcome', {
feedPosts: feedPosts.toArray(),
workItemGroups: workItems.groupBy(item => item.startDate.getFullYear()),
workItemYears: workItems.map(item => item.startDate.getFullYear())
.unique()
.toArray(),
workItemHiddenYears: workItems.filter(item => item.endDate)
.map(item => item.startDate.getFullYear())
.unique()
.toArray()
})
}
public async feed() {
const feedPosts = await this.getFeedPosts(true)
return view('feed', {
feedPosts: feedPosts.toArray(),
})
}
protected async getFeedPosts(all = false): Promise<Collection<FeedPost>> {
const query = FeedPost.query<FeedPost>()
.orderByDescending('posted_at')
if ( !all ) {
query.limit(6)
}
if ( !this.security.hasUser() ) {
query.where('visible', '=', true)
}
return query.get().collect()
}
protected async getWorkItems(): Promise<Collection<WorkItem>> {
const query = WorkItem.query<WorkItem>()
.orderByDescending('start_date')
if ( !this.security.hasUser() ) {
query.where('visible', '=', true)
}
return query.get().collect()
}
}