Skip to content

Commit

Permalink
Adding account authorization collection
Browse files Browse the repository at this point in the history
  • Loading branch information
erinharrington-12 committed Oct 26, 2023
1 parent 886cf3e commit d4e74d2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/collections.ts
Original file line number Diff line number Diff line change
@@ -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 ]);
export default new Set([ SCENE_COLLECTION, CHALLENGE_COLLECTION, CHALLENGE_COMPLETION_COLLECTION, ACCOUNT_AUTHORIZATION_COLLECTION ]);
10 changes: 9 additions & 1 deletion src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions src/model/Selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CHALLENGE_COLLECTION,
CHALLENGE_COMPLETION_COLLECTION,
BIG_STORE_COLLECTION,
ACCOUNT_AUTHORIZATION_COLLECTION
} from './constants';

interface Selector {
Expand Down Expand Up @@ -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;
3 changes: 2 additions & 1 deletion src/model/constants.ts
Original file line number Diff line number Diff line change
@@ -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';
export const CHALLENGE_COMPLETION_COLLECTION = 'challenge_completion';
export const ACCOUNT_AUTHORIZATION_COLLECTION = 'account_authorization';

0 comments on commit d4e74d2

Please sign in to comment.