fix sort by read time bug
This commit is contained in:
@ -1,8 +1,14 @@
|
||||
import * as httpContext from 'express-http-context2'
|
||||
import { EntityManager, EntityTarget } from 'typeorm'
|
||||
import { EntityManager, EntityTarget, Repository } from 'typeorm'
|
||||
import { appDataSource } from '../data_source'
|
||||
import { Claims } from '../resolvers/types'
|
||||
|
||||
export const getColumns = <T>(repository: Repository<T>): (keyof T)[] => {
|
||||
return repository.metadata.columns.map(
|
||||
(col) => col.propertyName
|
||||
) as (keyof T)[]
|
||||
}
|
||||
|
||||
export const setClaims = async (
|
||||
manager: EntityManager,
|
||||
uid = '00000000-0000-0000-0000-000000000000',
|
||||
|
||||
@ -49,6 +49,7 @@ import {
|
||||
UpdatesSinceError,
|
||||
UpdatesSinceSuccess,
|
||||
} from '../../generated/graphql'
|
||||
import { getColumns } from '../../repository'
|
||||
import { getInternalLabelWithColor } from '../../repository/label'
|
||||
import { libraryItemRepository } from '../../repository/library_item'
|
||||
import { userRepository } from '../../repository/user'
|
||||
@ -374,13 +375,17 @@ export const getArticleResolver = authorized<
|
||||
QueryArticleArgs
|
||||
>(async (_obj, { slug, format }, { authTrx, uid, log }, info) => {
|
||||
try {
|
||||
const selectColumns = getColumns(libraryItemRepository)
|
||||
const includeOriginalHtml =
|
||||
format === ArticleFormat.Distiller ||
|
||||
!!graphqlFields(info).article.originalHtml
|
||||
|
||||
if (!includeOriginalHtml) {
|
||||
selectColumns.splice(selectColumns.indexOf('originalContent'), 1)
|
||||
}
|
||||
// We allow the backend to use the ID instead of a slug to fetch the article
|
||||
const libraryItem = await authTrx((tx) =>
|
||||
tx.withRepository(libraryItemRepository).findOne({
|
||||
select: selectColumns,
|
||||
where: { slug },
|
||||
relations: {
|
||||
labels: true,
|
||||
|
||||
@ -89,7 +89,7 @@ export const subscriptionsResolver = authorized<
|
||||
}
|
||||
|
||||
const subscriptions = await queryBuilder
|
||||
.orderBy('subscription.' + sortBy, sortOrder)
|
||||
.orderBy(`subscription.${sortBy}`, sortOrder, 'NULLS LAST')
|
||||
.getMany()
|
||||
|
||||
return {
|
||||
|
||||
@ -97,8 +97,8 @@ const buildWhereClause = (
|
||||
}
|
||||
|
||||
if (args.typeFilter) {
|
||||
queryBuilder.andWhere('library_item.item_type = :typeFilter', {
|
||||
typeFilter: args.typeFilter,
|
||||
queryBuilder.andWhere('lower(library_item.item_type) = :typeFilter', {
|
||||
typeFilter: args.typeFilter.toLowerCase(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -108,7 +108,12 @@ const buildWhereClause = (
|
||||
queryBuilder.andWhere('library_item.archived_at IS NULL')
|
||||
break
|
||||
case InFilter.ARCHIVE:
|
||||
queryBuilder.andWhere('library_item.archived_at IS NOT NULL')
|
||||
queryBuilder.andWhere(
|
||||
'library_item.archived_at IS NOT NULL OR library_item.state = :state',
|
||||
{
|
||||
state: LibraryItemState.Archived,
|
||||
}
|
||||
)
|
||||
break
|
||||
case InFilter.TRASH:
|
||||
// return only deleted pages within 14 days
|
||||
@ -287,7 +292,7 @@ export const searchLibraryItems = async (
|
||||
buildWhereClause(queryBuilder, args)
|
||||
|
||||
const libraryItems = await queryBuilder
|
||||
.addOrderBy(`library_item.${sortField}`, sortOrder)
|
||||
.addOrderBy(`library_item.${sortField}`, sortOrder, 'NULLS LAST')
|
||||
.skip(from)
|
||||
.take(size)
|
||||
.getMany()
|
||||
|
||||
Reference in New Issue
Block a user