Skip to content

Commit

Permalink
minor: added firestoreDateBlockRange()
Browse files Browse the repository at this point in the history
  • Loading branch information
dereekb committed Aug 10, 2022
1 parent b5a16ec commit 67f2dba
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UNKNOWN_WEBSITE_LINK_TYPE, WebsiteLink, GrantedRole } from '@dereekb/model';
import { FirestoreModelKey } from '../collection/collection';
import { nowISODateString, toISODateString, toJsDate } from '@dereekb/date';
import { DateBlockRange, nowISODateString, toISODateString, toJsDate } from '@dereekb/date';
import {
ModelFieldMapFunctionsConfig,
GetterOrValue,
Expand Down Expand Up @@ -582,6 +582,37 @@ export function firestoreWebsiteLinkArray() {
});
}

// MARK: DateBlockRange
export const DEFAULT_DATE_BLOCK_RANGE: DateBlockRange = {
i: 0
};

export const assignDateBlockRangeFunction = assignValuesToPOJOFunction<DateBlockRange>({ keysFilter: ['i', 'to'], valueFilter: KeyValueTypleValueFilter.NULL });
export const firestoreDateBlockRangeAssignFn: MapFunction<DateBlockRange, DateBlockRange> = (input) => {
const block = assignDateBlockRangeFunction(DEFAULT_DATE_BLOCK_RANGE, input);

if (block.to == null) {
block.to = block.i;
}

return block;
};

export function firestoreDateBlockRange() {
return firestoreField<DateBlockRange, DateBlockRange>({
default: DEFAULT_DATE_BLOCK_RANGE,
fromData: firestoreDateBlockRangeAssignFn,
toData: firestoreDateBlockRangeAssignFn
});
}

// MARK: DateBlockRange Array
export function firestoreDateBlockRangeArray() {
return firestoreObjectArray({
firestoreField: firestoreDateBlockRange()
});
}

// MARK: Deprecated
export type FirestoreSetFieldConfig<T extends string | number> = DefaultMapConfiguredFirestoreFieldConfig<Set<T>, T[]>;

Expand Down

0 comments on commit 67f2dba

Please sign in to comment.