Dwayne Harris 5 years ago
parent
commit
3eb2f9df8d
  1. 4
      src/plugins/api/posts.ts
  2. 24
      src/schemas.ts
  3. 11
      src/types/collections.ts

4
src/plugins/api/posts.ts

@ -267,7 +267,7 @@ function postsByUserRoute(server: FastifyInstance<Server, IncomingMessage, Serve
if (blocks.length > 0) return unauthorizedError(reply)
}
const userPostsQuery = createQuerySpec(`SELECT p.id FROM Users p WHERE p.pk = @user AND p.t = @type`, { user: id, type: UserItemType.Post })
const userPostsQuery = createQuerySpec(`SELECT p.id, p.postId FROM Users p WHERE p.pk = @user AND p.t = @type`, { user: id, type: UserItemType.Post })
const userPosts = await queryItems<UserPost>({
container: userContainer,
query: userPostsQuery,
@ -277,7 +277,7 @@ function postsByUserRoute(server: FastifyInstance<Server, IncomingMessage, Serve
const posts = await queryItems<Post>({
container: containerFor(server.database.client, 'Posts'),
query: createQuerySpec('SELECT * FROM Posts p WHERE ARRAY_CONTAINS(@posts, p.id)', {
posts: userPosts.map(p => p.id!),
posts: userPosts.map(p => p.postId!),
}),
logger: request.log
})

24
src/schemas.ts

@ -10,18 +10,6 @@ export const tokenResponseSchema: JSONSchema = {
},
}
export const postSchema: JSONSchema = {
type: 'object',
properties: {
id: { type: 'string' },
userId: { type: 'string' },
text: { type: 'string' },
cover: { type: 'string' },
visible: { type: 'boolean' },
created: { type: 'number' },
},
}
export const awardSchema: JSONSchema = {
type: 'object',
properties: {
@ -74,6 +62,18 @@ export const userSchema: JSONSchema = {
},
}
export const postSchema: JSONSchema = {
type: 'object',
properties: {
id: { type: 'string' },
user: userSchema,
text: { type: 'string' },
cover: { type: 'string' },
visible: { type: 'boolean' },
created: { type: 'number' },
},
}
export const appSchema: JSONSchema = {
type: 'object',
properties: {

11
src/types/collections.ts

@ -267,6 +267,10 @@ export interface Status {
created: number
}
export interface PostData {
[key: string]: any
}
export interface Post {
id: string
pk: string // postId
@ -278,6 +282,7 @@ export interface Post {
cover?: string
attachments: PostAttachment[]
status?: Status
data?: PostData
visible: boolean
awards: number
latestAwards: PostAwardPartial[]
@ -311,12 +316,16 @@ export interface PostRelationship {
pk: string // root post ID
}
export interface InstallationSettings {
[key: string]: any
}
export interface Installation {
id: string
pk: typeof INSTALLATION_PARTITION_KEY
userId: string
appId: string
settings: object
settings: InstallationSettings
created: number
}

Loading…
Cancel
Save