From 3eb2f9df8d2b1c91634145e798f2e656e31c9ba3 Mon Sep 17 00:00:00 2001 From: Dwayne Harris Date: Sat, 26 Oct 2019 18:57:39 -0400 Subject: [PATCH] WIP --- src/plugins/api/posts.ts | 4 ++-- src/schemas.ts | 24 ++++++++++++------------ src/types/collections.ts | 11 ++++++++++- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/plugins/api/posts.ts b/src/plugins/api/posts.ts index 0c0f758..8e3eb65 100644 --- a/src/plugins/api/posts.ts +++ b/src/plugins/api/posts.ts @@ -267,7 +267,7 @@ function postsByUserRoute(server: FastifyInstance 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({ container: userContainer, query: userPostsQuery, @@ -277,7 +277,7 @@ function postsByUserRoute(server: FastifyInstance({ 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 }) diff --git a/src/schemas.ts b/src/schemas.ts index f9cdb00..4b326ca 100644 --- a/src/schemas.ts +++ b/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: { diff --git a/src/types/collections.ts b/src/types/collections.ts index 36e7bd2..45ed8cf 100644 --- a/src/types/collections.ts +++ b/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 }