Dwayne Harris 5 years ago
parent
commit
ccd73122c9
  1. 6
      src/lib/media.ts
  2. 12
      src/plugins/api/authentication.ts
  3. 11
      src/plugins/api/users.ts
  4. 86
      src/schemas.ts
  5. 1
      src/types/collections.ts

6
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) {

12
src/plugins/api/authentication.ts

@ -189,6 +189,7 @@ function registerRoute(server: FastifyInstance<Server, IncomingMessage, ServerRe
awards: 0,
points: 0,
balance: 0,
posts: 0,
subscriberCount: 0,
subscribedCount: 0,
pending: userPending,
@ -385,7 +386,16 @@ function selfRoute(server: FastifyInstance<Server, IncomingMessage, ServerRespon
})
if (!viewer) return unauthorizedError(reply)
return viewer
const group = viewer.group ? await getItem<Group>({
container: containerFor(server.database.client, 'Groups'),
id: viewer.group.id,
}) : undefined
return {
...viewer,
group,
}
})
}

11
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<Server, IncomingMessage, ServerRespons
if (blocks.length > 0) return unauthorizedError(reply)
}
return user
const group = user.group ? await getItem<Group>({
container: containerFor(server.database.client, 'Groups'),
id: user.group.id,
}) : undefined
return {
...user,
group,
}
})
}

86
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,
},
},
}

1
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

Loading…
Cancel
Save