2022-11-18 02:23:04 +00:00
|
|
|
import type {
|
|
|
|
FollowingEntity,
|
|
|
|
AuthResult,
|
|
|
|
ShoutInput,
|
|
|
|
Topic,
|
|
|
|
Author,
|
2022-11-24 06:52:31 +00:00
|
|
|
LoadShoutsOptions,
|
|
|
|
QueryLoadChatsArgs,
|
|
|
|
QueryLoadAuthorsByArgs,
|
2022-11-24 07:11:24 +00:00
|
|
|
QueryLoadMessagesByArgs,
|
|
|
|
MutationCreateChatArgs,
|
2022-11-24 12:58:07 +00:00
|
|
|
MutationCreateMessageArgs,
|
2022-12-01 17:16:14 +00:00
|
|
|
QueryLoadRecipientsArgs,
|
2023-01-20 04:40:55 +00:00
|
|
|
ProfileInput,
|
|
|
|
ReactionInput,
|
|
|
|
Chat,
|
2023-03-27 14:45:07 +00:00
|
|
|
ReactionBy,
|
2023-10-14 11:39:24 +00:00
|
|
|
Shout,
|
|
|
|
NotificationsQueryParams,
|
|
|
|
NotificationsQueryResult
|
2022-11-18 02:23:04 +00:00
|
|
|
} from '../graphql/types.gen'
|
2022-09-09 11:53:35 +00:00
|
|
|
import { publicGraphQLClient } from '../graphql/publicGraphQLClient'
|
2022-11-14 01:17:12 +00:00
|
|
|
import { getToken, privateGraphQLClient } from '../graphql/privateGraphQLClient'
|
2022-09-09 11:53:35 +00:00
|
|
|
import topicsAll from '../graphql/query/topics-all'
|
|
|
|
import mySession from '../graphql/mutation/my-session'
|
2022-09-17 18:23:30 +00:00
|
|
|
import authLogoutQuery from '../graphql/mutation/auth-logout'
|
|
|
|
import authLoginQuery from '../graphql/query/auth-login'
|
|
|
|
import authRegisterMutation from '../graphql/mutation/auth-register'
|
|
|
|
import authCheckEmailQuery from '../graphql/query/auth-check-email'
|
2022-10-21 18:17:04 +00:00
|
|
|
import authConfirmEmailMutation from '../graphql/mutation/auth-confirm-email'
|
2022-09-17 18:23:30 +00:00
|
|
|
import authSendLinkMutation from '../graphql/mutation/auth-send-link'
|
2022-09-09 11:53:35 +00:00
|
|
|
import followMutation from '../graphql/mutation/follow'
|
|
|
|
import unfollowMutation from '../graphql/mutation/unfollow'
|
|
|
|
import topicsRandomQuery from '../graphql/query/topics-random'
|
|
|
|
import authorsAll from '../graphql/query/authors-all'
|
|
|
|
import reactionCreate from '../graphql/mutation/reaction-create'
|
|
|
|
import reactionDestroy from '../graphql/mutation/reaction-destroy'
|
|
|
|
import reactionUpdate from '../graphql/mutation/reaction-update'
|
2022-11-09 17:57:35 +00:00
|
|
|
import createArticle from '../graphql/mutation/article-create'
|
2022-11-15 12:05:56 +00:00
|
|
|
import myChats from '../graphql/query/chats-load'
|
2022-11-15 15:27:02 +00:00
|
|
|
import chatMessagesLoadBy from '../graphql/query/chat-messages-load-by'
|
2022-11-14 17:41:05 +00:00
|
|
|
import authorBySlug from '../graphql/query/author-by-slug'
|
2023-02-13 13:48:05 +00:00
|
|
|
import userSubscribers from '../graphql/query/author-followers'
|
2023-04-22 14:36:38 +00:00
|
|
|
import userFollowedAuthors from '../graphql/query/author-following-users'
|
|
|
|
import userFollowedTopics from '../graphql/query/author-following-topics'
|
2022-11-13 19:35:57 +00:00
|
|
|
import topicBySlug from '../graphql/query/topic-by-slug'
|
2022-11-23 04:12:11 +00:00
|
|
|
import createChat from '../graphql/mutation/create-chat'
|
2022-11-15 15:27:02 +00:00
|
|
|
import reactionsLoadBy from '../graphql/query/reactions-load-by'
|
|
|
|
import authorsLoadBy from '../graphql/query/authors-load-by'
|
|
|
|
import shoutsLoadBy from '../graphql/query/articles-load-by'
|
2023-05-05 20:05:50 +00:00
|
|
|
import draftsLoad from '../graphql/query/drafts-load'
|
2022-11-27 11:00:44 +00:00
|
|
|
import shoutLoad from '../graphql/query/article-load'
|
2023-07-07 16:53:01 +00:00
|
|
|
import myFeed from '../graphql/query/my-feed'
|
2022-11-24 09:06:48 +00:00
|
|
|
import loadRecipients from '../graphql/query/chat-recipients'
|
2022-11-25 07:36:45 +00:00
|
|
|
import createMessage from '../graphql/mutation/create-chat-message'
|
2022-12-01 17:16:14 +00:00
|
|
|
import updateProfile from '../graphql/mutation/update-profile'
|
2023-04-20 13:58:56 +00:00
|
|
|
import updateArticle from '../graphql/mutation/article-update'
|
2023-05-08 17:21:06 +00:00
|
|
|
import deleteShout from '../graphql/mutation/article-delete'
|
2023-10-14 11:39:24 +00:00
|
|
|
import notifications from '../graphql/query/notifications'
|
|
|
|
import markNotificationAsRead from '../graphql/mutation/mark-notification-as-read'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-11-14 01:17:12 +00:00
|
|
|
type ApiErrorCode =
|
|
|
|
| 'unknown'
|
|
|
|
| 'email_not_confirmed'
|
|
|
|
| 'user_not_found'
|
|
|
|
| 'user_already_exists'
|
|
|
|
| 'token_expired'
|
|
|
|
| 'token_invalid'
|
2022-09-30 14:22:33 +00:00
|
|
|
|
|
|
|
export class ApiError extends Error {
|
|
|
|
code: ApiErrorCode
|
|
|
|
|
|
|
|
constructor(code: ApiErrorCode, message?: string) {
|
|
|
|
super(message)
|
|
|
|
this.code = code
|
|
|
|
}
|
|
|
|
}
|
2022-09-17 18:23:30 +00:00
|
|
|
|
2022-09-30 14:22:33 +00:00
|
|
|
export const apiClient = {
|
2022-11-13 19:35:57 +00:00
|
|
|
authLogin: async ({ email, password }: { email: string; password: string }): Promise<AuthResult> => {
|
2022-09-17 18:23:30 +00:00
|
|
|
const response = await publicGraphQLClient.query(authLoginQuery, { email, password }).toPromise()
|
2022-10-08 16:40:58 +00:00
|
|
|
// console.debug('[api-client] authLogin', { response })
|
2022-09-30 14:22:33 +00:00
|
|
|
if (response.error) {
|
2023-09-09 12:05:26 +00:00
|
|
|
if (
|
|
|
|
response.error.message === '[GraphQL] User not found' ||
|
|
|
|
response.error.message === "[GraphQL] 'dict' object has no attribute 'id'"
|
|
|
|
) {
|
2022-09-30 14:22:33 +00:00
|
|
|
throw new ApiError('user_not_found')
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new ApiError('unknown', response.error.message)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.data.signIn.error) {
|
|
|
|
if (response.data.signIn.error === 'please, confirm email') {
|
|
|
|
throw new ApiError('email_not_confirmed')
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new ApiError('unknown', response.data.signIn.error)
|
|
|
|
}
|
|
|
|
|
2022-09-17 18:23:30 +00:00
|
|
|
return response.data.signIn
|
|
|
|
},
|
2022-10-21 18:17:04 +00:00
|
|
|
authRegister: async ({
|
|
|
|
email,
|
|
|
|
password,
|
|
|
|
name
|
|
|
|
}: {
|
|
|
|
email: string
|
|
|
|
password: string
|
|
|
|
name: string
|
|
|
|
}): Promise<void> => {
|
2022-09-30 14:22:33 +00:00
|
|
|
const response = await publicGraphQLClient
|
2022-10-22 09:18:12 +00:00
|
|
|
.mutation(authRegisterMutation, { email, password, name })
|
2022-09-30 14:22:33 +00:00
|
|
|
.toPromise()
|
2022-10-21 18:17:04 +00:00
|
|
|
|
|
|
|
if (response.error) {
|
|
|
|
if (response.error.message === '[GraphQL] User already exist') {
|
|
|
|
throw new ApiError('user_already_exists', response.error.message)
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new ApiError('unknown', response.error.message)
|
|
|
|
}
|
2022-09-17 18:23:30 +00:00
|
|
|
},
|
|
|
|
authSignOut: async () => {
|
|
|
|
const response = await publicGraphQLClient.query(authLogoutQuery, {}).toPromise()
|
|
|
|
return response.data.signOut
|
|
|
|
},
|
|
|
|
authCheckEmail: async ({ email }) => {
|
|
|
|
// check if email is used
|
|
|
|
const response = await publicGraphQLClient.query(authCheckEmailQuery, { email }).toPromise()
|
|
|
|
return response.data.isEmailUsed
|
|
|
|
},
|
2022-11-27 19:19:06 +00:00
|
|
|
authSendLink: async ({ email, lang, template }) => {
|
2022-09-17 18:23:30 +00:00
|
|
|
// send link with code on email
|
2022-11-27 19:19:06 +00:00
|
|
|
const response = await publicGraphQLClient
|
|
|
|
.mutation(authSendLinkMutation, { email, lang, template })
|
|
|
|
.toPromise()
|
2022-11-13 19:35:57 +00:00
|
|
|
|
|
|
|
if (response.error) {
|
2022-11-14 01:17:12 +00:00
|
|
|
if (response.error.message === '[GraphQL] User not found') {
|
|
|
|
throw new ApiError('user_not_found', response.error.message)
|
|
|
|
}
|
|
|
|
|
2022-11-13 19:35:57 +00:00
|
|
|
throw new ApiError('unknown', response.error.message)
|
|
|
|
}
|
|
|
|
|
2022-11-14 01:17:12 +00:00
|
|
|
if (response.data.sendLink.error) {
|
|
|
|
throw new ApiError('unknown', response.data.sendLink.message)
|
|
|
|
}
|
|
|
|
|
2022-11-02 06:56:01 +00:00
|
|
|
return response.data.sendLink
|
2022-09-17 18:23:30 +00:00
|
|
|
},
|
2022-10-21 18:17:04 +00:00
|
|
|
confirmEmail: async ({ token }: { token: string }) => {
|
2022-09-17 18:23:30 +00:00
|
|
|
// confirm email with code from link
|
2022-10-25 16:25:42 +00:00
|
|
|
const response = await publicGraphQLClient.mutation(authConfirmEmailMutation, { token }).toPromise()
|
2022-10-21 18:17:04 +00:00
|
|
|
if (response.error) {
|
2022-11-14 01:17:12 +00:00
|
|
|
// TODO: better error communication
|
|
|
|
if (response.error.message === '[GraphQL] check token lifetime') {
|
|
|
|
throw new ApiError('token_expired', response.error.message)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.error.message === '[GraphQL] token is not valid') {
|
|
|
|
throw new ApiError('token_invalid', response.error.message)
|
|
|
|
}
|
|
|
|
|
2022-10-21 18:17:04 +00:00
|
|
|
throw new ApiError('unknown', response.error.message)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.data?.confirmEmail?.error) {
|
|
|
|
throw new ApiError('unknown', response.data?.confirmEmail?.error)
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.data.confirmEmail
|
2022-09-17 18:23:30 +00:00
|
|
|
},
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
getRandomTopics: async ({ amount }: { amount: number }) => {
|
|
|
|
const response = await publicGraphQLClient.query(topicsRandomQuery, { amount }).toPromise()
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-09-30 14:22:33 +00:00
|
|
|
if (!response.data) {
|
2022-10-08 16:40:58 +00:00
|
|
|
console.error('[api-client] getRandomTopics', response.error)
|
2022-09-30 14:22:33 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
return response.data.topicsRandom
|
|
|
|
},
|
|
|
|
|
|
|
|
// subscribe
|
|
|
|
|
|
|
|
follow: async ({ what, slug }: { what: FollowingEntity; slug: string }) => {
|
2022-12-01 18:45:35 +00:00
|
|
|
const response = await privateGraphQLClient.mutation(followMutation, { what, slug }).toPromise()
|
2022-09-09 11:53:35 +00:00
|
|
|
return response.data.follow
|
|
|
|
},
|
|
|
|
unfollow: async ({ what, slug }: { what: FollowingEntity; slug: string }) => {
|
2022-12-01 18:45:35 +00:00
|
|
|
const response = await privateGraphQLClient.mutation(unfollowMutation, { what, slug }).toPromise()
|
2022-09-09 11:53:35 +00:00
|
|
|
return response.data.unfollow
|
|
|
|
},
|
|
|
|
|
2022-09-30 14:22:33 +00:00
|
|
|
getSession: async (): Promise<AuthResult> => {
|
2022-11-14 01:17:12 +00:00
|
|
|
if (!getToken()) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
// renew session with auth token in header (!)
|
|
|
|
const response = await privateGraphQLClient.mutation(mySession, {}).toPromise()
|
2022-10-21 18:17:04 +00:00
|
|
|
|
|
|
|
if (response.error) {
|
|
|
|
throw new ApiError('unknown', response.error.message)
|
|
|
|
}
|
|
|
|
|
2022-11-24 14:59:37 +00:00
|
|
|
if (response.data?.getSession?.error) {
|
|
|
|
throw new ApiError('unknown', response.data.getSession.error)
|
2022-10-21 18:17:04 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 14:59:37 +00:00
|
|
|
return response.data.getSession
|
2022-09-09 11:53:35 +00:00
|
|
|
},
|
|
|
|
getAllTopics: async () => {
|
|
|
|
const response = await publicGraphQLClient.query(topicsAll, {}).toPromise()
|
2022-10-04 12:42:11 +00:00
|
|
|
if (response.error) {
|
2022-10-08 16:40:58 +00:00
|
|
|
console.debug('[api-client] getAllTopics', response.error)
|
2022-10-04 12:42:11 +00:00
|
|
|
}
|
2022-09-09 11:53:35 +00:00
|
|
|
return response.data.topicsAll
|
|
|
|
},
|
|
|
|
getAllAuthors: async () => {
|
2022-10-04 09:26:47 +00:00
|
|
|
const response = await publicGraphQLClient.query(authorsAll, {}).toPromise()
|
2022-10-04 12:42:11 +00:00
|
|
|
if (response.error) {
|
2022-10-08 16:40:58 +00:00
|
|
|
console.debug('[api-client] getAllAuthors', response.error)
|
2022-10-04 12:42:11 +00:00
|
|
|
}
|
2022-09-09 11:53:35 +00:00
|
|
|
return response.data.authorsAll
|
|
|
|
},
|
2022-11-13 19:35:57 +00:00
|
|
|
getAuthor: async ({ slug }: { slug: string }): Promise<Author> => {
|
|
|
|
const response = await publicGraphQLClient.query(authorBySlug, { slug }).toPromise()
|
|
|
|
return response.data.getAuthor
|
|
|
|
},
|
2023-02-13 13:48:05 +00:00
|
|
|
getAuthorFollowers: async ({ slug }: { slug: string }): Promise<Author[]> => {
|
|
|
|
const response = await publicGraphQLClient.query(userSubscribers, { slug }).toPromise()
|
|
|
|
return response.data.userFollowers
|
|
|
|
},
|
2023-04-22 14:36:38 +00:00
|
|
|
getAuthorFollowingUsers: async ({ slug }: { slug: string }): Promise<Author[]> => {
|
|
|
|
const response = await publicGraphQLClient.query(userFollowedAuthors, { slug }).toPromise()
|
|
|
|
return response.data.userFollowedAuthors
|
|
|
|
},
|
|
|
|
getAuthorFollowingTopics: async ({ slug }: { slug: string }): Promise<Topic[]> => {
|
|
|
|
const response = await publicGraphQLClient.query(userFollowedTopics, { slug }).toPromise()
|
|
|
|
return response.data.userFollowedTopics
|
2023-02-23 14:07:25 +00:00
|
|
|
},
|
2022-12-01 18:07:27 +00:00
|
|
|
updateProfile: async (input: ProfileInput) => {
|
|
|
|
const response = await privateGraphQLClient.mutation(updateProfile, { profile: input }).toPromise()
|
2022-12-07 08:37:40 +00:00
|
|
|
return response.data.updateProfile
|
2022-12-01 17:16:14 +00:00
|
|
|
},
|
2022-11-13 19:35:57 +00:00
|
|
|
getTopic: async ({ slug }: { slug: string }): Promise<Topic> => {
|
|
|
|
const response = await publicGraphQLClient.query(topicBySlug, { slug }).toPromise()
|
|
|
|
return response.data.getTopic
|
2022-10-04 12:42:11 +00:00
|
|
|
},
|
2023-03-27 14:45:07 +00:00
|
|
|
createArticle: async ({ article }: { article: ShoutInput }): Promise<Shout> => {
|
2022-11-09 17:57:35 +00:00
|
|
|
const response = await privateGraphQLClient.mutation(createArticle, { shout: article }).toPromise()
|
2023-03-27 14:45:07 +00:00
|
|
|
return response.data.createShout.shout
|
2022-11-09 17:57:35 +00:00
|
|
|
},
|
2023-05-07 15:15:30 +00:00
|
|
|
updateArticle: async ({
|
|
|
|
shoutId,
|
2023-05-08 17:21:06 +00:00
|
|
|
shoutInput,
|
|
|
|
publish
|
2023-05-07 15:15:30 +00:00
|
|
|
}: {
|
|
|
|
shoutId: number
|
2023-05-08 17:21:06 +00:00
|
|
|
shoutInput?: ShoutInput
|
|
|
|
publish: boolean
|
2023-05-07 15:15:30 +00:00
|
|
|
}): Promise<Shout> => {
|
2023-05-08 17:21:06 +00:00
|
|
|
const response = await privateGraphQLClient
|
|
|
|
.mutation(updateArticle, { shoutId, shoutInput, publish })
|
|
|
|
.toPromise()
|
2023-04-20 13:58:56 +00:00
|
|
|
console.debug('[updateArticle]:', response.data)
|
2023-05-05 20:05:50 +00:00
|
|
|
return response.data.updateShout.shout
|
2023-04-20 13:58:56 +00:00
|
|
|
},
|
2023-05-08 17:21:06 +00:00
|
|
|
deleteShout: async ({ shoutId }: { shoutId: number }): Promise<void> => {
|
|
|
|
const response = await privateGraphQLClient.mutation(deleteShout, { shoutId }).toPromise()
|
|
|
|
console.debug('[deleteShout]:', response)
|
2023-05-05 20:05:50 +00:00
|
|
|
},
|
|
|
|
getDrafts: async (): Promise<Shout[]> => {
|
|
|
|
const response = await privateGraphQLClient.query(draftsLoad, {}).toPromise()
|
|
|
|
console.debug('[getDrafts]:', response)
|
|
|
|
return response.data.loadDrafts
|
2023-05-01 18:32:32 +00:00
|
|
|
},
|
2023-01-20 04:40:55 +00:00
|
|
|
createReaction: async (input: ReactionInput) => {
|
|
|
|
const response = await privateGraphQLClient.mutation(reactionCreate, { reaction: input }).toPromise()
|
|
|
|
console.debug('[createReaction]:', response)
|
|
|
|
return response.data.createReaction.reaction
|
2022-09-09 11:53:35 +00:00
|
|
|
},
|
2023-01-20 04:40:55 +00:00
|
|
|
destroyReaction: async (id: number) => {
|
2023-02-07 12:48:45 +00:00
|
|
|
const response = await privateGraphQLClient.mutation(reactionDestroy, { id: id }).toPromise()
|
2023-01-20 04:40:55 +00:00
|
|
|
console.debug('[destroyReaction]:', response)
|
2023-02-17 09:21:02 +00:00
|
|
|
return response.data.deleteReaction.reaction
|
2022-09-09 11:53:35 +00:00
|
|
|
},
|
2023-02-07 12:48:45 +00:00
|
|
|
updateReaction: async (id: number, input: ReactionInput) => {
|
|
|
|
const response = await privateGraphQLClient
|
|
|
|
.mutation(reactionUpdate, { id: id, reaction: input })
|
|
|
|
.toPromise()
|
|
|
|
console.debug('[updateReaction]:', response)
|
|
|
|
return response.data.updateReaction.reaction
|
2022-09-14 11:28:43 +00:00
|
|
|
},
|
2022-11-24 06:52:31 +00:00
|
|
|
getAuthorsBy: async (options: QueryLoadAuthorsByArgs) => {
|
|
|
|
const resp = await publicGraphQLClient.query(authorsLoadBy, options).toPromise()
|
2022-11-18 02:23:04 +00:00
|
|
|
return resp.data.loadAuthorsBy
|
2022-11-13 09:25:31 +00:00
|
|
|
},
|
2023-05-08 17:21:06 +00:00
|
|
|
getShoutBySlug: async (slug: string) => {
|
2022-11-18 02:23:04 +00:00
|
|
|
const resp = await publicGraphQLClient
|
|
|
|
.query(shoutLoad, {
|
|
|
|
slug
|
|
|
|
})
|
|
|
|
.toPromise()
|
2023-05-08 17:21:06 +00:00
|
|
|
|
|
|
|
if (resp.error) {
|
|
|
|
console.error(resp)
|
|
|
|
}
|
|
|
|
|
2022-11-18 02:23:04 +00:00
|
|
|
return resp.data.loadShout
|
2022-11-13 09:25:31 +00:00
|
|
|
},
|
2023-05-08 17:21:06 +00:00
|
|
|
getShoutById: async (shoutId: number) => {
|
|
|
|
const resp = await publicGraphQLClient
|
|
|
|
.query(shoutLoad, {
|
|
|
|
shoutId
|
|
|
|
})
|
|
|
|
.toPromise()
|
|
|
|
|
|
|
|
if (resp.error) {
|
|
|
|
console.error(resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.data.loadShout
|
|
|
|
},
|
|
|
|
|
2022-11-18 02:23:04 +00:00
|
|
|
getShouts: async (options: LoadShoutsOptions) => {
|
2023-02-17 09:21:02 +00:00
|
|
|
const resp = await publicGraphQLClient.query(shoutsLoadBy, { options }).toPromise()
|
|
|
|
if (resp.error) {
|
|
|
|
console.error(resp)
|
|
|
|
}
|
|
|
|
|
2022-11-18 02:23:04 +00:00
|
|
|
return resp.data.loadShouts
|
|
|
|
},
|
2023-01-20 04:40:55 +00:00
|
|
|
|
2023-07-07 16:53:01 +00:00
|
|
|
getMyFeed: async (options: LoadShoutsOptions) => {
|
|
|
|
const resp = await privateGraphQLClient.query(myFeed, { options }).toPromise()
|
|
|
|
|
|
|
|
if (resp.error) {
|
|
|
|
console.error(resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.data.myFeed
|
|
|
|
},
|
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
getReactionsBy: async ({ by, limit }: { by: ReactionBy; limit?: number }) => {
|
|
|
|
const resp = await publicGraphQLClient
|
|
|
|
.query(reactionsLoadBy, { by, limit: limit ?? 1000, offset: 0 })
|
|
|
|
.toPromise()
|
2023-02-28 17:13:14 +00:00
|
|
|
// console.debug(resp)
|
2022-11-15 14:24:50 +00:00
|
|
|
return resp.data.loadReactionsBy
|
2022-11-14 09:48:26 +00:00
|
|
|
},
|
2023-10-14 11:39:24 +00:00
|
|
|
getNotifications: async (params: NotificationsQueryParams): Promise<NotificationsQueryResult> => {
|
|
|
|
const resp = await privateGraphQLClient.query(notifications, params).toPromise()
|
|
|
|
console.debug(resp.data)
|
|
|
|
return resp.data.loadNotifications
|
|
|
|
},
|
|
|
|
markNotificationAsRead: async (notificationId: number): Promise<void> => {
|
|
|
|
await privateGraphQLClient
|
|
|
|
.mutation(markNotificationAsRead, {
|
|
|
|
notificationId
|
|
|
|
})
|
|
|
|
.toPromise()
|
|
|
|
},
|
2022-11-16 06:33:58 +00:00
|
|
|
|
|
|
|
// inbox
|
2022-12-17 03:27:00 +00:00
|
|
|
getChats: async (options: QueryLoadChatsArgs): Promise<Chat[]> => {
|
2022-11-24 06:52:31 +00:00
|
|
|
const resp = await privateGraphQLClient.query(myChats, options).toPromise()
|
2022-11-27 07:10:04 +00:00
|
|
|
return resp.data.loadChats.chats
|
2022-11-16 06:33:58 +00:00
|
|
|
},
|
|
|
|
|
2022-11-25 07:36:45 +00:00
|
|
|
createChat: async (options: MutationCreateChatArgs) => {
|
|
|
|
const resp = await privateGraphQLClient.mutation(createChat, options).toPromise()
|
|
|
|
return resp.data.createChat
|
|
|
|
},
|
|
|
|
|
|
|
|
createMessage: async (options: MutationCreateMessageArgs) => {
|
|
|
|
const resp = await privateGraphQLClient.mutation(createMessage, options).toPromise()
|
2023-01-26 06:59:43 +00:00
|
|
|
return resp.data.createMessage.message
|
2022-11-25 07:36:45 +00:00
|
|
|
},
|
|
|
|
|
2022-11-24 06:52:31 +00:00
|
|
|
getChatMessages: async (options: QueryLoadMessagesByArgs) => {
|
|
|
|
const resp = await privateGraphQLClient.query(chatMessagesLoadBy, options).toPromise()
|
2023-01-26 06:59:43 +00:00
|
|
|
return resp.data.loadMessagesBy.messages
|
2022-11-24 09:06:48 +00:00
|
|
|
},
|
2022-11-24 12:58:07 +00:00
|
|
|
getRecipients: async (options: QueryLoadRecipientsArgs) => {
|
|
|
|
const resp = await privateGraphQLClient.query(loadRecipients, options).toPromise()
|
|
|
|
return resp.data.loadRecipients.members
|
2022-09-09 11:53:35 +00:00
|
|
|
}
|
|
|
|
}
|