mirror of
https://github.com/standardnotes/server
synced 2026-09-13 00:45:26 -04:00
wip: e2e tests
This commit is contained in:
@@ -37,7 +37,7 @@ export class ItemsController extends BaseHttpController {
|
||||
computeIntegrityHash: request.body.compute_integrity === true,
|
||||
syncToken: request.body.sync_token,
|
||||
cursorToken: request.body.cursor_token,
|
||||
groupUuid: request.body.group_uuid,
|
||||
groupUuids: request.body.group_uuids,
|
||||
limit: request.body.limit,
|
||||
contentType: request.body.content_type,
|
||||
apiVersion: request.body.api ?? ApiVersion.v20161215,
|
||||
|
||||
@@ -4,5 +4,5 @@ export type GetItemsDTO = {
|
||||
cursorToken?: string | null
|
||||
limit?: number
|
||||
contentType?: string
|
||||
groupUuid?: string | null
|
||||
groupUuids?: string[] | null
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export type ItemQuery = {
|
||||
syncTimeComparison?: '>' | '>='
|
||||
contentType?: string | string[]
|
||||
includeGroupUuids?: string[]
|
||||
exclusiveGroupUuid?: string | null
|
||||
exclusiveGroupUuids?: string[] | null
|
||||
deleted?: boolean
|
||||
offset?: number
|
||||
limit?: number
|
||||
|
||||
@@ -50,11 +50,14 @@ export class ItemService implements ItemServiceInterface {
|
||||
|
||||
const groupUsers = await this.groupUsersRepository.findAll({ userUuid: dto.userUuid })
|
||||
const userGroupUuids = groupUsers.map((groupUser) => groupUser.groupUuid)
|
||||
const exclusiveGroupUuids = dto.groupUuids
|
||||
? dto.groupUuids.filter((groupUuid) => userGroupUuids.includes(groupUuid))
|
||||
: undefined
|
||||
|
||||
const itemQuery: ItemQuery = {
|
||||
userUuid: dto.userUuid,
|
||||
includeGroupUuids: !dto.groupUuid ? userGroupUuids : undefined,
|
||||
exclusiveGroupUuid: dto.groupUuid && userGroupUuids.includes(dto.groupUuid) ? dto.groupUuid : undefined,
|
||||
includeGroupUuids: !dto.groupUuids ? userGroupUuids : undefined,
|
||||
exclusiveGroupUuids: exclusiveGroupUuids,
|
||||
lastSyncTime,
|
||||
syncTimeComparison,
|
||||
contentType: dto.contentType,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { GroupUserKey } from '../GroupUserKey/Model/GroupUserKey'
|
||||
import { GroupUserKeyServiceInterface } from '../GroupUserKey/Service/GroupUserKeyServiceInterface'
|
||||
import { Item } from '../Item/Item'
|
||||
import { ItemConflict } from '../Item/ItemConflict'
|
||||
@@ -13,7 +14,7 @@ export class SyncItems implements UseCaseInterface {
|
||||
const getItemsResult = await this.itemService.getItems({
|
||||
userUuid: dto.userUuid,
|
||||
syncToken: dto.syncToken,
|
||||
groupUuid: dto.groupUuid,
|
||||
groupUuids: dto.groupUuids,
|
||||
cursorToken: dto.cursorToken,
|
||||
limit: dto.limit,
|
||||
contentType: dto.contentType,
|
||||
@@ -28,19 +29,24 @@ export class SyncItems implements UseCaseInterface {
|
||||
})
|
||||
|
||||
let retrievedItems = this.filterOutSyncConflictsForConsecutiveSyncs(getItemsResult.items, saveItemsResult.conflicts)
|
||||
if (this.isFirstSync(dto)) {
|
||||
const isGroupExclusiveSync = dto.groupUuids && dto.groupUuids.length > 0
|
||||
if (this.isFirstSync(dto) && !isGroupExclusiveSync) {
|
||||
retrievedItems = await this.itemService.frontLoadKeysItemsToTop(dto.userUuid, retrievedItems)
|
||||
}
|
||||
|
||||
const lastSyncTime = this.itemService.getLastSyncTime({
|
||||
syncToken: dto.syncToken,
|
||||
cursorToken: dto.cursorToken,
|
||||
})
|
||||
let newUserKeys: GroupUserKey[] = []
|
||||
const isNotPerformingGroupSpecificSync = dto.groupUuids == undefined || dto.groupUuids.length === 0
|
||||
if (isNotPerformingGroupSpecificSync) {
|
||||
const lastSyncTime = this.itemService.getLastSyncTime({
|
||||
syncToken: dto.syncToken,
|
||||
cursorToken: dto.cursorToken,
|
||||
})
|
||||
|
||||
const groupKeys = await this.groupUserService.getGroupUserKeysForUser({
|
||||
userUuid: dto.userUuid,
|
||||
lastSyncTime,
|
||||
})
|
||||
newUserKeys = await this.groupUserService.getGroupUserKeysForUser({
|
||||
userUuid: dto.userUuid,
|
||||
lastSyncTime,
|
||||
})
|
||||
}
|
||||
|
||||
const syncResponse: SyncItemsResponse = {
|
||||
retrievedItems,
|
||||
@@ -48,7 +54,7 @@ export class SyncItems implements UseCaseInterface {
|
||||
savedItems: saveItemsResult.savedItems,
|
||||
conflicts: saveItemsResult.conflicts,
|
||||
cursorToken: getItemsResult.cursorToken,
|
||||
groupKeys,
|
||||
groupKeys: newUserKeys,
|
||||
}
|
||||
|
||||
return syncResponse
|
||||
|
||||
@@ -5,7 +5,7 @@ export type SyncItemsDTO = {
|
||||
itemHashes: Array<ItemHash>
|
||||
computeIntegrityHash: boolean
|
||||
limit: number
|
||||
groupUuid?: string | null
|
||||
groupUuids?: string[] | null
|
||||
syncToken?: string | null
|
||||
cursorToken?: string | null
|
||||
contentType?: string
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Repository, SelectQueryBuilder } from 'typeorm'
|
||||
import { Brackets, Repository, SelectQueryBuilder } from 'typeorm'
|
||||
import { Item } from '../../Domain/Item/Item'
|
||||
import { ItemQuery } from '../../Domain/Item/ItemQuery'
|
||||
import { ItemRepositoryInterface } from '../../Domain/Item/ItemRepositoryInterface'
|
||||
@@ -132,18 +132,20 @@ export class TypeORMItemRepository implements ItemRepositoryInterface {
|
||||
}
|
||||
|
||||
if (query.includeGroupUuids != undefined && query.includeGroupUuids.length > 0) {
|
||||
queryBuilder.where('item.group_uuid IN (:...groupUuids)', { groupUuids: query.includeGroupUuids })
|
||||
if (query.userUuid) {
|
||||
queryBuilder.orWhere('item.user_uuid = :userUuid', { userUuid: query.userUuid })
|
||||
}
|
||||
queryBuilder.where(
|
||||
new Brackets((qb) => {
|
||||
qb.where('item.group_uuid IN (:...groupUuids)', { groupUuids: query.includeGroupUuids })
|
||||
if (query.userUuid) {
|
||||
qb.orWhere('item.user_uuid = :userUuid', { userUuid: query.userUuid })
|
||||
}
|
||||
}),
|
||||
)
|
||||
} else if (query.exclusiveGroupUuids != undefined && query.exclusiveGroupUuids.length > 0) {
|
||||
queryBuilder.andWhere('item.group_uuid IN (:...groupUuids)', { groupUuids: query.exclusiveGroupUuids })
|
||||
} else if (query.userUuid !== undefined) {
|
||||
queryBuilder.where('item.user_uuid = :userUuid', { userUuid: query.userUuid })
|
||||
}
|
||||
|
||||
if (query.exclusiveGroupUuid) {
|
||||
queryBuilder.andWhere('item.group_uuid = :groupUuid', { groupUuid: query.exclusiveGroupUuid })
|
||||
}
|
||||
|
||||
if (query.selectString !== undefined) {
|
||||
queryBuilder.select(query.selectString)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user