From ccd73122c9dc6d7c8c4038e1b7cd3a77241f5088 Mon Sep 17 00:00:00 2001 From: Dwayne Harris Date: Fri, 18 Oct 2019 23:56:04 -0400 Subject: [PATCH] WIP --- src/lib/media.ts | 6 ++- src/plugins/api/authentication.ts | 12 ++++- src/plugins/api/users.ts | 11 +++- src/schemas.ts | 86 ++++++++++++++----------------- src/types/collections.ts | 1 + 5 files changed, 66 insertions(+), 50 deletions(-) diff --git a/src/lib/media.ts b/src/lib/media.ts index d539ab3..23204e1 100644 --- a/src/lib/media.ts +++ b/src/lib/media.ts @@ -22,7 +22,11 @@ export async function deleteMedia(name: string) { BlockBlobURL.newPipeline(new SharedKeyCredential(process.env.BLOB_STORAGE_ACCOUNT!, process.env.BLOB_STORAGE_ACCOUNT_KEY!)) ) - await blockBlobURL.delete(Aborter.none) + try { + await blockBlobURL.delete(Aborter.none) + } catch (e) { + + } } export async function attachMedia(container: Container, name: string) { diff --git a/src/plugins/api/authentication.ts b/src/plugins/api/authentication.ts index 6825e8f..1866617 100644 --- a/src/plugins/api/authentication.ts +++ b/src/plugins/api/authentication.ts @@ -189,6 +189,7 @@ function registerRoute(server: FastifyInstance({ + container: containerFor(server.database.client, 'Groups'), + id: viewer.group.id, + }) : undefined + + return { + ...viewer, + group, + } }) } diff --git a/src/plugins/api/users.ts b/src/plugins/api/users.ts index fba9aed..2e99084 100644 --- a/src/plugins/api/users.ts +++ b/src/plugins/api/users.ts @@ -27,6 +27,7 @@ import { UserItemType, GroupItemType, BlockType, + Group, } from '../../types/collections' import { PluginOptions } from '../../types' @@ -198,7 +199,15 @@ function getRoute(server: FastifyInstance 0) return unauthorizedError(reply) } - return user + const group = user.group ? await getItem({ + container: containerFor(server.database.client, 'Groups'), + id: user.group.id, + }) : undefined + + return { + ...user, + group, + } }) } diff --git a/src/schemas.ts b/src/schemas.ts index 9e9cc69..f9cdb00 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -22,7 +22,18 @@ export const postSchema: JSONSchema = { }, } -export const userSchema: JSONSchema = { +export const awardSchema: JSONSchema = { + type: 'object', + properties: { + userId: { type: 'string' }, + imageUrl: { type: 'string' }, + text: { type: 'string' }, + userText: { type: 'string' }, + created: { type: 'number' }, + }, +} + +export const groupListingSchema: JSONSchema = { type: 'object', properties: { id: { type: 'string' }, @@ -30,16 +41,35 @@ export const userSchema: JSONSchema = { about: { type: 'string' }, imageUrl: { type: 'string' }, coverImageUrl: { type: 'string' }, - group: { - type: 'object', - properties: { - id: { type: 'string' }, - name: { type: 'string' }, - iconImageUrl: { type: 'string' }, - }, + iconImageUrl: { type: 'string' }, + requiresApproval: { type: 'boolean' }, + members: { type: 'number' }, + posts: { type: 'number' }, + awards: { type: 'number' }, + points: { type: 'number' }, + created: { type: 'number' }, + membership: { type: 'string' }, + latestAwards: { + type: 'array', + items: awardSchema, }, + }, +} + +export const userSchema: JSONSchema = { + type: 'object', + properties: { + id: { type: 'string' }, + name: { type: 'string' }, + about: { type: 'string' }, + imageUrl: { type: 'string' }, + coverImageUrl: { type: 'string' }, + group: groupListingSchema, subscription: { type: 'string' }, membership: { type: 'string' }, + posts: { type: 'number' }, + awards: { type: 'number' }, + points: { type: 'number' }, created: { type: 'number' }, }, } @@ -85,52 +115,14 @@ export const selfSchema: JSONSchema = { about: { type: 'string' }, imageUrl: { type: 'string' }, coverImageUrl: { type: 'string' }, - group: { - type: 'object', - properties: { - id: { type: 'string' }, - name: { type: 'string' }, - iconImageUrl: { type: 'string' }, - }, - }, + group: groupListingSchema, requiresApproval: { type: 'boolean' }, privacy: { type: 'string' }, membership: { type: 'string' }, - created: { type: 'number' }, - }, -} - -export const awardSchema: JSONSchema = { - type: 'object', - properties: { - userId: { type: 'string' }, - imageUrl: { type: 'string' }, - text: { type: 'string' }, - userText: { type: 'string' }, - created: { type: 'number' }, - }, -} - -export const groupListingSchema: JSONSchema = { - type: 'object', - properties: { - id: { type: 'string' }, - name: { type: 'string' }, - about: { type: 'string' }, - imageUrl: { type: 'string' }, - coverImageUrl: { type: 'string' }, - iconImageUrl: { type: 'string' }, - requiresApproval: { type: 'boolean' }, - members: { type: 'number' }, posts: { type: 'number' }, awards: { type: 'number' }, points: { type: 'number' }, created: { type: 'number' }, - membership: { type: 'string' }, - latestAwards: { - type: 'array', - items: awardSchema, - }, }, } diff --git a/src/types/collections.ts b/src/types/collections.ts index c1da985..36e7bd2 100644 --- a/src/types/collections.ts +++ b/src/types/collections.ts @@ -188,6 +188,7 @@ export interface User { awards: number // Total Awards points: number balance: number // Currency (Flex) + posts: number subscriberCount: number subscribedCount: number pending: boolean