Standardize query auth check

This commit is contained in:
Sam Becker 2024-06-20 00:08:28 -05:00
parent ee95719f8c
commit e16dbb80a4
2 changed files with 7 additions and 4 deletions

View File

@ -9,7 +9,7 @@ import {
getPhoto,
getPhotos,
} from '@/photo/db/query';
import { GetPhotosOptions } from './db';
import { GetPhotosOptions, areOptionsSensitive } from './db';
import {
PhotoFormData,
convertFormDataToPhotoDbInsert,
@ -392,13 +392,13 @@ export const getPhotosHiddenMetaCachedAction = async () =>
// Public/Private actions
export const getPhotosAction = async (options: GetPhotosOptions) =>
(options.hidden === 'include' || options.hidden === 'only')
areOptionsSensitive(options)
? runAuthenticatedAdminServerAction(() => getPhotos(options))
: getPhotos(options);
export const getPhotosCachedAction = async (options: GetPhotosOptions) =>
(options.hidden === 'include' || options.hidden === 'only')
? runAuthenticatedAdminServerAction(() => getPhotosCached (options))
areOptionsSensitive(options)
? runAuthenticatedAdminServerAction(() => getPhotosCached(options))
: getPhotosCached(options);
// Public actions

View File

@ -23,6 +23,9 @@ export type GetPhotosOptions = {
hidden?: 'exclude' | 'include' | 'only'
};
export const areOptionsSensitive = (options: GetPhotosOptions) =>
options.hidden === 'include' || options.hidden === 'only';
export const getWheresFromOptions = (
options: GetPhotosOptions,
initialValuesIndex = 1