This commit is contained in:
Bastian Wagner
2026-06-17 10:34:30 +02:00
parent 3998923693
commit f77a592fc8
21 changed files with 637 additions and 6 deletions

View File

@@ -91,13 +91,34 @@ export class InMemoryRepository<T extends object> {
return recordValue === null || recordValue === undefined;
}
if (value instanceof FindOperator && value.type === 'lessThanOrEqual') {
const operatorValue = value.value as unknown;
if (recordValue instanceof Date && operatorValue instanceof Date) {
return recordValue.getTime() <= operatorValue.getTime();
}
if (
(typeof recordValue === 'number' || typeof recordValue === 'string') &&
(typeof operatorValue === 'number' || typeof operatorValue === 'string')
) {
return recordValue <= operatorValue;
}
return false;
}
return recordValue === value;
});
}
private applyOrder(records: T[], order: unknown): T[] {
const sortedRecords = [...records];
const typedOrder = order as { name?: 'ASC' | 'DESC'; items?: { position?: 'ASC' | 'DESC' } };
const typedOrder = order as {
name?: 'ASC' | 'DESC';
reminderAt?: 'ASC' | 'DESC';
items?: { position?: 'ASC' | 'DESC' };
};
if (typedOrder?.name) {
sortedRecords.sort((left, right) => {
@@ -109,6 +130,18 @@ export class InMemoryRepository<T extends object> {
});
}
if (typedOrder?.reminderAt) {
sortedRecords.sort((left, right) => {
const leftDate = (left as Record<string, unknown>)['reminderAt'];
const rightDate = (right as Record<string, unknown>)['reminderAt'];
const leftTime = leftDate instanceof Date ? leftDate.getTime() : 0;
const rightTime = rightDate instanceof Date ? rightDate.getTime() : 0;
return typedOrder.reminderAt === 'DESC'
? rightTime - leftTime
: leftTime - rightTime;
});
}
if (typedOrder?.items?.position) {
for (const record of sortedRecords) {
const items = (record as { items?: Array<{ position: number }> }).items;