Skip to content

Commit

Permalink
탬플릿 gql
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-maki committed Jun 10, 2024
1 parent 599a9a8 commit 3d6e40b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/website/src/lib/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const PostState = {
DRAFT: 'DRAFT',
EPHEMERAL: 'EPHEMERAL',
PUBLISHED: 'PUBLISHED',
TEMPLATE: 'TEMPLATE',
} as const;

export const PostSynchronizationKind = {
Expand Down
14 changes: 10 additions & 4 deletions apps/website/src/lib/server/graphql/schemas/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
BookmarkGroups,
database,
inArray,
notInArray,
PostComments,
PostContentSnapshots,
PostContentStates,
Expand Down Expand Up @@ -980,6 +981,7 @@ const CreatePostInput = builder.inputType('CreatePostInput', {
fields: (t) => ({
spaceId: t.id({ required: false }),
collectionId: t.id({ required: false }),
isTemplate: t.boolean({ defaultValue: false }),
}),
});

Expand Down Expand Up @@ -1262,7 +1264,7 @@ builder.mutationFields((t) => ({
permalink,
userId: context.session.userId,
spaceId: input.spaceId,
state: 'EPHEMERAL',
state: input.isTemplate ? 'TEMPLATE' : 'EPHEMERAL',
visibility: 'PUBLIC',
discloseStats: true,
receiveFeedback: true,
Expand Down Expand Up @@ -1327,7 +1329,7 @@ builder.mutationFields((t) => ({
.where(
and(
eq(Posts.id, input.postId),
ne(Posts.state, 'DELETED'),
notInArray(Posts.state, ['DELETED', 'TEMPLATE']),
or(eq(Spaces.state, 'ACTIVE'), isNull(Spaces.id)),
),
);
Expand Down Expand Up @@ -1496,7 +1498,9 @@ builder.mutationFields((t) => ({
.select({ userId: Posts.userId, space: { id: Spaces.id } })
.from(Posts)
.innerJoin(Spaces, eq(Spaces.id, Posts.spaceId))
.where(and(eq(Posts.id, input.postId), eq(Posts.state, 'PUBLISHED'), eq(Spaces.state, 'ACTIVE')));
.where(
and(eq(Posts.id, input.postId), inArray(Posts.state, ['PUBLISHED', 'TEMPLATE']), eq(Spaces.state, 'ACTIVE')),
);

if (posts.length === 0) {
throw new NotFoundError();
Expand Down Expand Up @@ -1542,7 +1546,9 @@ builder.mutationFields((t) => ({
.select({ userId: Posts.userId, space: { id: Spaces.id } })
.from(Posts)
.innerJoin(Spaces, eq(Spaces.id, Posts.spaceId))
.where(and(eq(Posts.id, input.postId), eq(Posts.state, 'PUBLISHED'), eq(Spaces.state, 'ACTIVE')));
.where(
and(eq(Posts.id, input.postId), inArray(Posts.state, ['PUBLISHED', 'TEMPLATE']), eq(Spaces.state, 'ACTIVE')),
);

if (posts.length === 0) {
throw new NotFoundError();
Expand Down

0 comments on commit 3d6e40b

Please sign in to comment.