|
|
@ -39,9 +39,9 @@ function postRoute(server: fastify.FastifyInstance<Server, IncomingMessage, Serv |
|
|
|
type: 'object', |
|
|
|
required: ['date'], |
|
|
|
properties: { |
|
|
|
imageUrl: 'string', |
|
|
|
text: 'string', |
|
|
|
date: 'number', |
|
|
|
imageUrl: { type: 'string' }, |
|
|
|
text: { type: 'string' }, |
|
|
|
date: { type: 'number' }, |
|
|
|
}, |
|
|
|
}, |
|
|
|
attachments: { |
|
|
@ -50,9 +50,9 @@ function postRoute(server: fastify.FastifyInstance<Server, IncomingMessage, Serv |
|
|
|
type: 'object', |
|
|
|
required: ['imageUrl'], |
|
|
|
properties: { |
|
|
|
imageUrl: 'string', |
|
|
|
caption: 'string', |
|
|
|
cover: 'string', |
|
|
|
imageUrl: { type: 'string' }, |
|
|
|
caption: { type: 'string' }, |
|
|
|
cover: { type: 'string' }, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
@ -77,7 +77,7 @@ function postRoute(server: fastify.FastifyInstance<Server, IncomingMessage, Serv |
|
|
|
|
|
|
|
const postContainer = await containerFor(server.database.client, 'Posts') |
|
|
|
const postRelationshipContainer = await containerFor(server.database.client, 'PostRelationships') |
|
|
|
const userContainer = await containerFor(server.database.client, 'User') |
|
|
|
const userContainer = await containerFor(server.database.client, 'Users') |
|
|
|
|
|
|
|
const postId = createPostId() |
|
|
|
|
|
|
@ -89,12 +89,13 @@ function postRoute(server: fastify.FastifyInstance<Server, IncomingMessage, Serv |
|
|
|
|
|
|
|
const parentRelationshipItem = postRelationshipContainer.item(request.body.parent, parent.root) |
|
|
|
const { resource: parentRelationship } = await parentRelationshipItem.read<IPostRelationship>() |
|
|
|
const parents = parentRelationship ? parentRelationship.parents : [] |
|
|
|
|
|
|
|
newPostRelationship = { |
|
|
|
id: postId, |
|
|
|
partitionKey: parent.root, |
|
|
|
parents: [ |
|
|
|
...parentRelationship.parents, |
|
|
|
...parents, |
|
|
|
parent.id, |
|
|
|
] |
|
|
|
} |
|
|
@ -121,9 +122,10 @@ function postRoute(server: fastify.FastifyInstance<Server, IncomingMessage, Serv |
|
|
|
|
|
|
|
await postContainer.items.create<IPost>(post) |
|
|
|
await userContainer.items.create<IUserPost>(userPost) |
|
|
|
await postRelationshipContainer.items.create<IPostRelationship>(newPostRelationship) |
|
|
|
|
|
|
|
const query = createQuerySpec(`SELECT u.id FROM Users u WHERE u.partitionKey = @partitionKey AND type = 'follow'`, { partitionKey: request.user.id }) |
|
|
|
if (newPostRelationship) await postRelationshipContainer.items.create<IPostRelationship>(newPostRelationship) |
|
|
|
|
|
|
|
const query = createQuerySpec(`SELECT u.id FROM Users u WHERE u.partitionKey = @partitionKey AND u.type = 'follow'`, { partitionKey: request.user.id }) |
|
|
|
const { resources: followers } = await userContainer.items.query<IUserFollow>(query, {}).fetchAll() |
|
|
|
|
|
|
|
if (followers.length < 500) { |
|
|
@ -136,6 +138,10 @@ function postRoute(server: fastify.FastifyInstance<Server, IncomingMessage, Serv |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
id: postId, |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|