From d4e74d275493f33c4563f84468867bea796014fe Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 26 Oct 2023 12:09:40 -0500 Subject: [PATCH] Adding account authorization collection --- src/collections.ts | 4 ++-- src/db.ts | 10 +++++++++- src/model/Selector.ts | 6 ++++++ src/model/constants.ts | 3 ++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/collections.ts b/src/collections.ts index 89d7280..b0a7f4e 100644 --- a/src/collections.ts +++ b/src/collections.ts @@ -1,3 +1,3 @@ -import { CHALLENGE_COLLECTION, CHALLENGE_COMPLETION_COLLECTION, SCENE_COLLECTION } from './model/constants'; +import { ACCOUNT_AUTHORIZATION_COLLECTION, CHALLENGE_COLLECTION, CHALLENGE_COMPLETION_COLLECTION, SCENE_COLLECTION } from './model/constants'; -export default new Set([ SCENE_COLLECTION, CHALLENGE_COLLECTION, CHALLENGE_COMPLETION_COLLECTION ]); \ No newline at end of file +export default new Set([ SCENE_COLLECTION, CHALLENGE_COLLECTION, CHALLENGE_COMPLETION_COLLECTION, ACCOUNT_AUTHORIZATION_COLLECTION ]); \ No newline at end of file diff --git a/src/db.ts b/src/db.ts index c66bd1d..7b85856 100644 --- a/src/db.ts +++ b/src/db.ts @@ -7,7 +7,7 @@ import Error from './model/Error'; import List from './model/List'; import firestore from './firestore'; import Cache from './Cache'; -import { CHALLENGE_COMPLETION_COLLECTION } from './model/constants'; +import { CHALLENGE_COMPLETION_COLLECTION, ACCOUNT_AUTHORIZATION_COLLECTION } from './model/constants'; const USER_ID_REQUIRED = new Set([ CHALLENGE_COMPLETION_COLLECTION, @@ -36,7 +36,15 @@ class Db { return `user/${userId}/${selector.collection}`; } + if (selector.collection === ACCOUNT_AUTHORIZATION_COLLECTION) { + if (!userId) throw { + type: 'error', + message: 'User ID is required for this collection.', + code: Error.CODE_NOT_AUTHORIZED, + } as Error; + return `user/${userId}/${selector.collection}`; + } return selector.collection; } diff --git a/src/model/Selector.ts b/src/model/Selector.ts index 61fc954..5d7568c 100644 --- a/src/model/Selector.ts +++ b/src/model/Selector.ts @@ -3,6 +3,7 @@ import { CHALLENGE_COLLECTION, CHALLENGE_COMPLETION_COLLECTION, BIG_STORE_COLLECTION, + ACCOUNT_AUTHORIZATION_COLLECTION } from './constants'; interface Selector { @@ -30,6 +31,11 @@ namespace Selector { collection: BIG_STORE_COLLECTION, id, }); + + export const accountAuthorization = (id: string): Selector => ({ + collection: ACCOUNT_AUTHORIZATION_COLLECTION, + id, + }); } export default Selector; \ No newline at end of file diff --git a/src/model/constants.ts b/src/model/constants.ts index 1dc956c..e0a8ffe 100644 --- a/src/model/constants.ts +++ b/src/model/constants.ts @@ -1,4 +1,5 @@ export const BIG_STORE_COLLECTION = 'big_store'; export const SCENE_COLLECTION = 'scene'; export const CHALLENGE_COLLECTION = 'challenge'; -export const CHALLENGE_COMPLETION_COLLECTION = 'challenge_completion'; \ No newline at end of file +export const CHALLENGE_COMPLETION_COLLECTION = 'challenge_completion'; +export const ACCOUNT_AUTHORIZATION_COLLECTION = 'account_authorization'; \ No newline at end of file