Updated permissions to have a key to group them
This commit is contained in:
@@ -16,12 +16,13 @@ import {
|
||||
Permission,
|
||||
PermissionType,
|
||||
permissions,
|
||||
PermissionTopic,
|
||||
} from "@/interfaces/permissions";
|
||||
import {v4} from "uuid";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
const db = getFirestore(app);
|
||||
|
||||
async function createPermission(type: string) {
|
||||
async function createPermission(topic: string, type: string) {
|
||||
const permData = doc(db, "permissions", v4());
|
||||
const permDoc = await getDoc(permData);
|
||||
if (permDoc.exists()) {
|
||||
@@ -30,9 +31,14 @@ async function createPermission(type: string) {
|
||||
|
||||
await setDoc(permData, {
|
||||
type,
|
||||
topic,
|
||||
users: [],
|
||||
});
|
||||
}
|
||||
interface PermissionsHelperList {
|
||||
topic: string;
|
||||
type: string;
|
||||
}
|
||||
export function getPermissions(userId: string | undefined, docs: Permission[]) {
|
||||
if (!userId) {
|
||||
return [];
|
||||
@@ -52,9 +58,19 @@ export function getPermissions(userId: string | undefined, docs: Permission[]) {
|
||||
}
|
||||
|
||||
export async function bootstrap() {
|
||||
await permissions.forEach(async (type) => {
|
||||
await createPermission(type);
|
||||
});
|
||||
await permissions
|
||||
.reduce((accm: PermissionsHelperList[], permissionData) => {
|
||||
return [
|
||||
...accm,
|
||||
...permissionData.list.map((type) => ({
|
||||
topic: permissionData.topic,
|
||||
type,
|
||||
})),
|
||||
];
|
||||
}, [])
|
||||
.forEach(async ({ topic, type }) => {
|
||||
await createPermission(topic, type);
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPermissionDoc(id: string) {
|
||||
|
||||
Reference in New Issue
Block a user