From da0045428ac3a9ce08658073d324ecef530631f4 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Mon, 5 Jan 2026 15:49:19 +0700 Subject: [PATCH] feat: temporal - huge refactor --- apps/backend/src/api/api.module.ts | 6 - .../src/api/routes/agencies.controller.ts | 37 - .../src/api/routes/analytics.controller.ts | 47 +- .../src/api/routes/marketplace.controller.ts | 242 ----- .../src/api/routes/messages.controller.ts | 50 - .../src/api/routes/monitor.controller.ts | 26 +- .../src/api/routes/posts.controller.ts | 17 - .../src/api/routes/settings.controller.ts | 87 -- .../src/api/routes/stripe.controller.ts | 37 - apps/backend/src/app.module.ts | 3 - apps/backend/src/main.ts | 8 +- apps/commands/src/command.module.ts | 6 +- apps/commands/src/tasks/check.stars.ts | 52 - apps/cron/.gitignore | 8 - apps/cron/nest-cli.json | 20 - apps/cron/package.json | 14 - apps/cron/src/cron.module.ts | 20 - apps/cron/src/main.ts | 12 - apps/cron/src/tasks/.gitkeep | 0 apps/cron/src/tasks/check.missing.queues.ts | 45 - .../cron/src/tasks/post.now.pending.queues.ts | 43 - apps/cron/tsconfig.build.json | 23 - apps/cron/tsconfig.json | 13 - .../components/layout/settings.component.tsx | 1 - .../components/marketplace/buyer.seller.tsx | 40 - .../src/components/marketplace/buyer.tsx | 568 ----------- .../marketplace/marketplace.provider.tsx | 36 - .../components/marketplace/marketplace.tsx | 3 - .../src/components/marketplace/order.list.tsx | 79 -- .../marketplace/order.top.actions.tsx | 387 -------- .../marketplace/preview.popup.dynamic.tsx | 19 - .../src/components/marketplace/seller.tsx | 241 ----- .../marketplace/special.message.tsx | 430 -------- .../src/components/messages/layout.tsx | 123 --- .../src/components/messages/messages.tsx | 285 ------ .../src/activities/autopost.activity.ts | 27 + .../src/activities/email.activity.ts | 23 + apps/orchestrator/src/app.module.ts | 8 +- apps/orchestrator/src/signals/email.signal.ts | 9 + .../src/workflows/autopost.workflow.ts | 30 + .../src/workflows/digest.email.workflow.ts | 69 ++ apps/orchestrator/src/workflows/index.ts | 2 + .../src/workflows/post.workflow.ts | 38 +- apps/workers/.gitignore | 8 - apps/workers/.swcrc | 38 - apps/workers/nest-cli.json | 20 - apps/workers/package.json | 14 - apps/workers/src/app/app.module.ts | 15 - apps/workers/src/app/posts.controller.ts | 54 -- apps/workers/src/main.ts | 25 - apps/workers/tsconfig.build.json | 23 - apps/workers/tsconfig.json | 11 - .../helpers/src/utils/concurrency.service.ts | 52 - .../bull-mq-transport-new/bull.mq.module.ts | 9 - .../src/bull-mq-transport-new/client.ts | 121 --- .../src/bull-mq-transport-new/strategy.ts | 61 -- .../prisma/autopost/autopost.service.ts | 48 +- .../src/database/prisma/database.module.ts | 12 - .../integrations/integration.service.ts | 11 +- .../marketplace/item.user.repository.ts | 41 - .../prisma/marketplace/item.user.service.ts | 15 - .../prisma/marketplace/messages.repository.ts | 915 ------------------ .../prisma/marketplace/messages.service.ts | 252 ----- .../database/prisma/marketplace/tags.list.ts | 138 --- .../notifications/notification.service.ts | 64 +- .../organizations/organization.repository.ts | 2 + .../database/prisma/posts/posts.service.ts | 168 +--- .../src/database/prisma/schema.prisma | 1 - .../database/prisma/stars/stars.repository.ts | 198 ---- .../database/prisma/stars/stars.service.ts | 485 ---------- .../subscriptions/subscription.service.ts | 33 - .../database/prisma/users/users.repository.ts | 92 -- .../database/prisma/users/users.service.ts | 13 - .../prisma/webhooks/webhooks.service.ts | 78 +- .../dtos/marketplace/add.remove.item.dto.ts | 11 - .../src/dtos/marketplace/audience.dto.ts | 8 - .../src/dtos/marketplace/change.active.dto.ts | 6 - .../src/dtos/marketplace/create.offer.dto.ts | 27 - .../src/dtos/marketplace/items.dto.ts | 12 - .../dtos/marketplace/new.conversation.dto.ts | 10 - .../src/dtos/messages/add.message.ts | 7 - .../src/integrations/integration.manager.ts | 3 +- .../src/integrations/social.abstract.ts | 42 +- .../integrations/social/bluesky.provider.ts | 270 +++--- .../integrations/social/discord.provider.ts | 153 ++- .../integrations/social/facebook.provider.ts | 74 +- .../integrations/social/instagram.provider.ts | 101 +- .../social/instagram.standalone.provider.ts | 19 + .../social/linkedin.page.provider.ts | 19 + .../integrations/social/linkedin.provider.ts | 43 +- .../social/mastodon.custom.provider.ts | 19 + .../integrations/social/mastodon.provider.ts | 134 ++- .../integrations/social/reddit.provider.ts | 93 +- .../integrations/social/threads.provider.ts | 91 +- .../src/integrations/social/x.provider.ts | 193 ++-- .../src/services/email.service.ts | 1 - .../src/services/stripe.service.ts | 144 --- .../src/services/trending.service.ts | 31 - .../nestjs-libraries/src/services/trending.ts | 217 ----- .../src/temporal/temporal.module.ts | 31 +- package.json | 13 +- pnpm-lock.yaml | 19 +- tsconfig.base.json | 2 - 103 files changed, 1108 insertions(+), 6936 deletions(-) delete mode 100644 apps/backend/src/api/routes/agencies.controller.ts delete mode 100644 apps/backend/src/api/routes/marketplace.controller.ts delete mode 100644 apps/backend/src/api/routes/messages.controller.ts delete mode 100644 apps/commands/src/tasks/check.stars.ts delete mode 100644 apps/cron/.gitignore delete mode 100644 apps/cron/nest-cli.json delete mode 100644 apps/cron/package.json delete mode 100644 apps/cron/src/cron.module.ts delete mode 100644 apps/cron/src/main.ts delete mode 100644 apps/cron/src/tasks/.gitkeep delete mode 100644 apps/cron/src/tasks/check.missing.queues.ts delete mode 100644 apps/cron/src/tasks/post.now.pending.queues.ts delete mode 100644 apps/cron/tsconfig.build.json delete mode 100644 apps/cron/tsconfig.json delete mode 100644 apps/frontend/src/components/marketplace/buyer.seller.tsx delete mode 100644 apps/frontend/src/components/marketplace/buyer.tsx delete mode 100644 apps/frontend/src/components/marketplace/marketplace.provider.tsx delete mode 100644 apps/frontend/src/components/marketplace/marketplace.tsx delete mode 100644 apps/frontend/src/components/marketplace/order.list.tsx delete mode 100644 apps/frontend/src/components/marketplace/order.top.actions.tsx delete mode 100644 apps/frontend/src/components/marketplace/preview.popup.dynamic.tsx delete mode 100644 apps/frontend/src/components/marketplace/seller.tsx delete mode 100644 apps/frontend/src/components/marketplace/special.message.tsx delete mode 100644 apps/frontend/src/components/messages/layout.tsx delete mode 100644 apps/frontend/src/components/messages/messages.tsx create mode 100644 apps/orchestrator/src/activities/autopost.activity.ts create mode 100644 apps/orchestrator/src/activities/email.activity.ts create mode 100644 apps/orchestrator/src/signals/email.signal.ts create mode 100644 apps/orchestrator/src/workflows/autopost.workflow.ts create mode 100644 apps/orchestrator/src/workflows/digest.email.workflow.ts delete mode 100644 apps/workers/.gitignore delete mode 100644 apps/workers/.swcrc delete mode 100644 apps/workers/nest-cli.json delete mode 100644 apps/workers/package.json delete mode 100644 apps/workers/src/app/app.module.ts delete mode 100644 apps/workers/src/app/posts.controller.ts delete mode 100644 apps/workers/src/main.ts delete mode 100644 apps/workers/tsconfig.build.json delete mode 100644 apps/workers/tsconfig.json delete mode 100644 libraries/helpers/src/utils/concurrency.service.ts delete mode 100644 libraries/nestjs-libraries/src/bull-mq-transport-new/bull.mq.module.ts delete mode 100644 libraries/nestjs-libraries/src/bull-mq-transport-new/client.ts delete mode 100644 libraries/nestjs-libraries/src/bull-mq-transport-new/strategy.ts delete mode 100644 libraries/nestjs-libraries/src/database/prisma/marketplace/item.user.repository.ts delete mode 100644 libraries/nestjs-libraries/src/database/prisma/marketplace/item.user.service.ts delete mode 100644 libraries/nestjs-libraries/src/database/prisma/marketplace/messages.repository.ts delete mode 100644 libraries/nestjs-libraries/src/database/prisma/marketplace/messages.service.ts delete mode 100644 libraries/nestjs-libraries/src/database/prisma/marketplace/tags.list.ts delete mode 100644 libraries/nestjs-libraries/src/database/prisma/stars/stars.repository.ts delete mode 100644 libraries/nestjs-libraries/src/database/prisma/stars/stars.service.ts delete mode 100644 libraries/nestjs-libraries/src/dtos/marketplace/add.remove.item.dto.ts delete mode 100644 libraries/nestjs-libraries/src/dtos/marketplace/audience.dto.ts delete mode 100644 libraries/nestjs-libraries/src/dtos/marketplace/change.active.dto.ts delete mode 100644 libraries/nestjs-libraries/src/dtos/marketplace/create.offer.dto.ts delete mode 100644 libraries/nestjs-libraries/src/dtos/marketplace/items.dto.ts delete mode 100644 libraries/nestjs-libraries/src/dtos/marketplace/new.conversation.dto.ts delete mode 100644 libraries/nestjs-libraries/src/dtos/messages/add.message.ts delete mode 100644 libraries/nestjs-libraries/src/services/trending.service.ts delete mode 100644 libraries/nestjs-libraries/src/services/trending.ts diff --git a/apps/backend/src/api/api.module.ts b/apps/backend/src/api/api.module.ts index 586dcd2f..291479c7 100644 --- a/apps/backend/src/api/api.module.ts +++ b/apps/backend/src/api/api.module.ts @@ -16,13 +16,10 @@ import { MediaController } from '@gitroom/backend/api/routes/media.controller'; import { UploadModule } from '@gitroom/nestjs-libraries/upload/upload.module'; import { BillingController } from '@gitroom/backend/api/routes/billing.controller'; import { NotificationsController } from '@gitroom/backend/api/routes/notifications.controller'; -import { MarketplaceController } from '@gitroom/backend/api/routes/marketplace.controller'; -import { MessagesController } from '@gitroom/backend/api/routes/messages.controller'; import { OpenaiService } from '@gitroom/nestjs-libraries/openai/openai.service'; import { ExtractContentService } from '@gitroom/nestjs-libraries/openai/extract.content.service'; import { CodesService } from '@gitroom/nestjs-libraries/services/codes.service'; import { CopilotController } from '@gitroom/backend/api/routes/copilot.controller'; -import { AgenciesController } from '@gitroom/backend/api/routes/agencies.controller'; import { PublicController } from '@gitroom/backend/api/routes/public.controller'; import { RootController } from '@gitroom/backend/api/routes/root.controller'; import { TrackService } from '@gitroom/nestjs-libraries/track/track.service'; @@ -44,10 +41,7 @@ const authenticatedController = [ MediaController, BillingController, NotificationsController, - MarketplaceController, - MessagesController, CopilotController, - AgenciesController, WebhookController, SignatureController, AutopostController, diff --git a/apps/backend/src/api/routes/agencies.controller.ts b/apps/backend/src/api/routes/agencies.controller.ts deleted file mode 100644 index e2849f96..00000000 --- a/apps/backend/src/api/routes/agencies.controller.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Body, Controller, Get, Param, Post } from '@nestjs/common'; -import { User } from '@prisma/client'; -import { ApiTags } from '@nestjs/swagger'; -import { AgenciesService } from '@gitroom/nestjs-libraries/database/prisma/agencies/agencies.service'; -import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request'; -import { CreateAgencyDto } from '@gitroom/nestjs-libraries/dtos/agencies/create.agency.dto'; - -@ApiTags('Agencies') -@Controller('/agencies') -export class AgenciesController { - constructor(private _agenciesService: AgenciesService) {} - @Get('/') - async getAgencyByUser(@GetUserFromRequest() user: User) { - return (await this._agenciesService.getAgencyByUser(user)) || {}; - } - - @Post('/') - async createAgency( - @GetUserFromRequest() user: User, - @Body() body: CreateAgencyDto - ) { - return this._agenciesService.createAgency(user, body); - } - - @Post('/action/:action/:id') - async updateAgency( - @GetUserFromRequest() user: User, - @Param('action') action: string, - @Param('id') id: string - ) { - if (!user.isSuperAdmin) { - return 400; - } - - return this._agenciesService.approveOrDecline(user.email, action, id); - } -} diff --git a/apps/backend/src/api/routes/analytics.controller.ts b/apps/backend/src/api/routes/analytics.controller.ts index 98caae8c..8c3201ef 100644 --- a/apps/backend/src/api/routes/analytics.controller.ts +++ b/apps/backend/src/api/routes/analytics.controller.ts @@ -1,56 +1,13 @@ -import { - Body, - Controller, - Get, - Inject, - Param, - Post, - Query, -} from '@nestjs/common'; +import { Controller, Get, Param, Query } from '@nestjs/common'; import { Organization } from '@prisma/client'; import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request'; -import { StarsService } from '@gitroom/nestjs-libraries/database/prisma/stars/stars.service'; -import dayjs from 'dayjs'; -import { StarsListDto } from '@gitroom/nestjs-libraries/dtos/analytics/stars.list.dto'; import { ApiTags } from '@nestjs/swagger'; import { IntegrationService } from '@gitroom/nestjs-libraries/database/prisma/integrations/integration.service'; -import { IntegrationManager } from '@gitroom/nestjs-libraries/integrations/integration.manager'; @ApiTags('Analytics') @Controller('/analytics') export class AnalyticsController { - constructor( - private _starsService: StarsService, - private _integrationService: IntegrationService - ) {} - @Get('/') - async getStars(@GetOrgFromRequest() org: Organization) { - return this._starsService.getStars(org.id); - } - - @Get('/trending') - async getTrending() { - const todayTrending = dayjs(dayjs().format('YYYY-MM-DDT12:00:00')); - const last = todayTrending.isAfter(dayjs()) - ? todayTrending.subtract(1, 'day') - : todayTrending; - const nextTrending = last.add(1, 'day'); - - return { - last: last.format('YYYY-MM-DD HH:mm:ss'), - predictions: nextTrending.format('YYYY-MM-DD HH:mm:ss'), - }; - } - - @Post('/stars') - async getStarsFilter( - @GetOrgFromRequest() org: Organization, - @Body() starsFilter: StarsListDto - ) { - return { - stars: await this._starsService.getStarsFilter(org.id, starsFilter), - }; - } + constructor(private _integrationService: IntegrationService) {} @Get('/:integration') async getIntegration( diff --git a/apps/backend/src/api/routes/marketplace.controller.ts b/apps/backend/src/api/routes/marketplace.controller.ts deleted file mode 100644 index afb961e9..00000000 --- a/apps/backend/src/api/routes/marketplace.controller.ts +++ /dev/null @@ -1,242 +0,0 @@ -import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common'; -import { Organization, User } from '@prisma/client'; -import { ApiTags } from '@nestjs/swagger'; -import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request'; -import { ItemUserService } from '@gitroom/nestjs-libraries/database/prisma/marketplace/item.user.service'; -import { AddRemoveItemDto } from '@gitroom/nestjs-libraries/dtos/marketplace/add.remove.item.dto'; -import { StripeService } from '@gitroom/nestjs-libraries/services/stripe.service'; -import { UsersService } from '@gitroom/nestjs-libraries/database/prisma/users/users.service'; -import { ChangeActiveDto } from '@gitroom/nestjs-libraries/dtos/marketplace/change.active.dto'; -import { ItemsDto } from '@gitroom/nestjs-libraries/dtos/marketplace/items.dto'; -import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request'; -import { AudienceDto } from '@gitroom/nestjs-libraries/dtos/marketplace/audience.dto'; -import { NewConversationDto } from '@gitroom/nestjs-libraries/dtos/marketplace/new.conversation.dto'; -import { MessagesService } from '@gitroom/nestjs-libraries/database/prisma/marketplace/messages.service'; -import { CreateOfferDto } from '@gitroom/nestjs-libraries/dtos/marketplace/create.offer.dto'; -import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service'; - -@ApiTags('Marketplace') -@Controller('/marketplace') -export class MarketplaceController { - constructor( - private _itemUserService: ItemUserService, - private _stripeService: StripeService, - private _userService: UsersService, - private _messagesService: MessagesService, - private _postsService: PostsService - ) {} - - @Post('/') - getInfluencers( - @GetOrgFromRequest() organization: Organization, - @GetUserFromRequest() user: User, - @Body() body: ItemsDto - ) { - return this._userService.getMarketplacePeople( - organization.id, - user.id, - body - ); - } - - @Post('/conversation') - createConversation( - @GetUserFromRequest() user: User, - @GetOrgFromRequest() organization: Organization, - @Body() body: NewConversationDto - ) { - return this._messagesService.createConversation( - user.id, - organization.id, - body - ); - } - - @Get('/bank') - connectBankAccount( - @GetUserFromRequest() user: User, - @Query('country') country: string - ) { - return this._stripeService.createAccountProcess( - user.id, - user.email, - country - ); - } - - @Post('/item') - async addItems( - @GetUserFromRequest() user: User, - @Body() body: AddRemoveItemDto - ) { - return this._itemUserService.addOrRemoveItem(body.state, user.id, body.key); - } - - @Post('/active') - async changeActive( - @GetUserFromRequest() user: User, - @Body() body: ChangeActiveDto - ) { - await this._userService.changeMarketplaceActive(user.id, body.active); - } - - @Post('/audience') - async changeAudience( - @GetUserFromRequest() user: User, - @Body() body: AudienceDto - ) { - await this._userService.changeAudienceSize(user.id, body.audience); - } - - @Get('/item') - async getItems(@GetUserFromRequest() user: User) { - return this._itemUserService.getItems(user.id); - } - - @Get('/orders') - async getOrders( - @GetUserFromRequest() user: User, - @GetOrgFromRequest() organization: Organization, - @Query('type') type: 'seller' | 'buyer' - ) { - return this._messagesService.getOrders(user.id, organization.id, type); - } - - @Get('/account') - async getAccount(@GetUserFromRequest() user: User) { - const { account, marketplace, connectedAccount, name, picture, audience } = - await this._userService.getUserByEmail(user.email); - return { - account, - marketplace, - connectedAccount, - fullname: name, - audience, - picture, - }; - } - - @Post('/offer') - async createOffer( - @GetUserFromRequest() user: User, - @Body() body: CreateOfferDto - ) { - return this._messagesService.createOffer(user.id, body); - } - - @Get('/posts/:id') - async post( - @GetUserFromRequest() user: User, - @GetOrgFromRequest() organization: Organization, - @Param('id') id: string - ) { - const getPost = await this._messagesService.getPost( - user.id, - organization.id, - id - ); - if (!getPost) { - return; - } - - return { - ...(await this._postsService.getPost(getPost.organizationId, id)), - providerId: getPost.integration.providerIdentifier, - }; - } - - @Post('/posts/:id/revision') - async revision( - @GetUserFromRequest() user: User, - @GetOrgFromRequest() organization: Organization, - @Param('id') id: string, - @Body('message') message: string - ) { - return this._messagesService.requestRevision( - user.id, - organization.id, - id, - message - ); - } - - @Post('/posts/:id/approve') - async approve( - @GetUserFromRequest() user: User, - @GetOrgFromRequest() organization: Organization, - @Param('id') id: string, - @Body('message') message: string - ) { - return this._messagesService.requestApproved( - user.id, - organization.id, - id, - message - ); - } - - @Post('/posts/:id/cancel') - async cancel( - @GetOrgFromRequest() organization: Organization, - @Param('id') id: string - ) { - return this._messagesService.requestCancel(organization.id, id); - } - - @Post('/offer/:id/complete') - async completeOrder( - @GetOrgFromRequest() organization: Organization, - @Param('id') id: string - ) { - const order = await this._messagesService.completeOrderAndPay( - organization.id, - id - ); - - if (!order) { - return; - } - - try { - await this._stripeService.payout( - id, - order.charge, - order.account, - order.price - ); - } catch (e) { - await this._messagesService.payoutProblem( - id, - order.sellerId, - order.price - ); - } - await this._messagesService.completeOrder(id); - } - - @Post('/orders/:id/payment') - async payOrder( - @GetUserFromRequest() user: User, - @GetOrgFromRequest() organization: Organization, - @Param('id') id: string - ) { - const orderDetails = await this._messagesService.getOrderDetails( - user.id, - organization.id, - id - ); - const payment = await this._stripeService.payAccountStepOne( - user.id, - organization, - orderDetails.seller, - orderDetails.order.id, - orderDetails.order.ordersItems.map((p) => ({ - quantity: p.quantity, - integrationType: p.integration.providerIdentifier, - price: p.price, - })), - orderDetails.order.messageGroupId - ); - return payment; - } -} diff --git a/apps/backend/src/api/routes/messages.controller.ts b/apps/backend/src/api/routes/messages.controller.ts deleted file mode 100644 index 2af0d9b0..00000000 --- a/apps/backend/src/api/routes/messages.controller.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Body, Controller, Get, Param, Post } from '@nestjs/common'; -import { ApiTags } from '@nestjs/swagger'; -import { MessagesService } from '@gitroom/nestjs-libraries/database/prisma/marketplace/messages.service'; -import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request'; -import { Organization, User } from '@prisma/client'; -import { AddMessageDto } from '@gitroom/nestjs-libraries/dtos/messages/add.message'; -import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request'; - -@ApiTags('Messages') -@Controller('/messages') -export class MessagesController { - constructor(private _messagesService: MessagesService) {} - - @Get('/') - getMessagesGroup( - @GetUserFromRequest() user: User, - @GetOrgFromRequest() organization: Organization - ) { - return this._messagesService.getMessagesGroup(user.id, organization.id); - } - - @Get('/:groupId/:page') - getMessages( - @GetUserFromRequest() user: User, - @GetOrgFromRequest() organization: Organization, - @Param('groupId') groupId: string, - @Param('page') page: string - ) { - return this._messagesService.getMessages( - user.id, - organization.id, - groupId, - +page - ); - } - @Post('/:groupId') - createMessage( - @GetUserFromRequest() user: User, - @GetOrgFromRequest() organization: Organization, - @Param('groupId') groupId: string, - @Body() message: AddMessageDto - ) { - return this._messagesService.createMessage( - user.id, - organization.id, - groupId, - message - ); - } -} diff --git a/apps/backend/src/api/routes/monitor.controller.ts b/apps/backend/src/api/routes/monitor.controller.ts index 6409def7..df4a857c 100644 --- a/apps/backend/src/api/routes/monitor.controller.ts +++ b/apps/backend/src/api/routes/monitor.controller.ts @@ -1,30 +1,14 @@ -import { Controller, Get, HttpException, Param } from '@nestjs/common'; +import { Controller, Get, Param } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; -import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/client'; @ApiTags('Monitor') @Controller('/monitor') export class MonitorController { - constructor(private _workerServiceProducer: BullMqClient) {} - @Get('/queue/:name') async getMessagesGroup(@Param('name') name: string) { - const { valid } = - await this._workerServiceProducer.checkForStuckWaitingJobs(name); - - if (valid) { - return { - status: 'success', - message: `Queue ${name} is healthy.`, - }; - } - - throw new HttpException( - { - status: 'error', - message: `Queue ${name} has stuck waiting jobs.`, - }, - 503 - ); + return { + status: 'success', + message: `Queue ${name} is healthy.`, + }; } } diff --git a/apps/backend/src/api/routes/posts.controller.ts b/apps/backend/src/api/routes/posts.controller.ts index 18cd1bfa..c51852ee 100644 --- a/apps/backend/src/api/routes/posts.controller.ts +++ b/apps/backend/src/api/routes/posts.controller.ts @@ -13,10 +13,8 @@ import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/po import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request'; import { Organization, User } from '@prisma/client'; import { GetPostsDto } from '@gitroom/nestjs-libraries/dtos/posts/get.posts.dto'; -import { StarsService } from '@gitroom/nestjs-libraries/database/prisma/stars/stars.service'; import { CheckPolicies } from '@gitroom/backend/services/auth/permissions/permissions.ability'; import { ApiTags } from '@nestjs/swagger'; -import { MessagesService } from '@gitroom/nestjs-libraries/database/prisma/marketplace/messages.service'; import { GeneratorDto } from '@gitroom/nestjs-libraries/dtos/generator/generator.dto'; import { CreateGeneratedPostsDto } from '@gitroom/nestjs-libraries/dtos/generator/create.generated.posts.dto'; import { AgentGraphService } from '@gitroom/nestjs-libraries/agent/agent.graph.service'; @@ -31,8 +29,6 @@ import { AuthorizationActions, Sections } from '@gitroom/backend/services/auth/p export class PostsController { constructor( private _postsService: PostsService, - private _starsService: StarsService, - private _messagesService: MessagesService, private _agentGraphService: AgentGraphService, private _shortLinkService: ShortLinkService ) {} @@ -50,14 +46,6 @@ export class PostsController { return { ask: this._shortLinkService.askShortLinkedin(body.messages) }; } - @Get('/marketplace/:id') - async getMarketplacePosts( - @GetOrgFromRequest() org: Organization, - @Param('id') id: string - ) { - return this._messagesService.getMarketplaceAvailableOffers(org.id, id); - } - @Post('/:id/comments') async createComment( @GetOrgFromRequest() org: Organization, @@ -115,11 +103,6 @@ export class PostsController { return { date: await this._postsService.findFreeDateTime(org.id, id) }; } - @Get('/predict-trending') - predictTrending() { - return this._starsService.predictTrending(); - } - @Get('/old') oldPosts( @GetOrgFromRequest() org: Organization, diff --git a/apps/backend/src/api/routes/settings.controller.ts b/apps/backend/src/api/routes/settings.controller.ts index bcc5044e..c92537b4 100644 --- a/apps/backend/src/api/routes/settings.controller.ts +++ b/apps/backend/src/api/routes/settings.controller.ts @@ -1,7 +1,6 @@ import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common'; import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request'; import { Organization } from '@prisma/client'; -import { StarsService } from '@gitroom/nestjs-libraries/database/prisma/stars/stars.service'; import { CheckPolicies } from '@gitroom/backend/services/auth/permissions/permissions.ability'; import { OrganizationService } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.service'; import { AddTeamMemberDto } from '@gitroom/nestjs-libraries/dtos/settings/add.team.member.dto'; @@ -12,95 +11,9 @@ import { AuthorizationActions, Sections } from '@gitroom/backend/services/auth/p @Controller('/settings') export class SettingsController { constructor( - private _starsService: StarsService, private _organizationService: OrganizationService ) {} - @Get('/github') - @CheckPolicies([AuthorizationActions.Create, Sections.ADMIN]) - async getConnectedGithubAccounts(@GetOrgFromRequest() org: Organization) { - return { - github: ( - await this._starsService.getGitHubRepositoriesByOrgId(org.id) - ).map((repo) => ({ - id: repo.id, - login: repo.login, - })), - }; - } - - @Post('/github') - @CheckPolicies([AuthorizationActions.Create, Sections.ADMIN]) - async addGitHub( - @GetOrgFromRequest() org: Organization, - @Body('code') code: string - ) { - if (!code) { - throw new Error('No code provided'); - } - await this._starsService.addGitHub(org.id, code); - } - - @Get('/github/url') - @CheckPolicies([AuthorizationActions.Create, Sections.ADMIN]) - authUrl() { - return { - url: `https://github.com/login/oauth/authorize?client_id=${ - process.env.GITHUB_CLIENT_ID - }&scope=${encodeURIComponent( - 'user:email' - )}&redirect_uri=${encodeURIComponent( - `${process.env.FRONTEND_URL}/settings` - )}`, - }; - } - - @Get('/organizations/:id') - @CheckPolicies([AuthorizationActions.Create, Sections.ADMIN]) - async getOrganizations( - @GetOrgFromRequest() org: Organization, - @Param('id') id: string - ) { - return { - organizations: await this._starsService.getOrganizations(org.id, id), - }; - } - - @Get('/organizations/:id/:github') - @CheckPolicies([AuthorizationActions.Create, Sections.ADMIN]) - async getRepositories( - @GetOrgFromRequest() org: Organization, - @Param('id') id: string, - @Param('github') github: string - ) { - return { - repositories: await this._starsService.getRepositoriesOfOrganization( - org.id, - id, - github - ), - }; - } - - @Post('/organizations/:id') - @CheckPolicies([AuthorizationActions.Create, Sections.ADMIN]) - async updateGitHubLogin( - @GetOrgFromRequest() org: Organization, - @Param('id') id: string, - @Body('login') login: string - ) { - return this._starsService.updateGitHubLogin(org.id, id, login); - } - - @Delete('/repository/:id') - @CheckPolicies([AuthorizationActions.Create, Sections.ADMIN]) - async deleteRepository( - @GetOrgFromRequest() org: Organization, - @Param('id') id: string - ) { - return this._starsService.deleteRepository(org.id, id); - } - @Get('/team') @CheckPolicies( [AuthorizationActions.Create, Sections.TEAM_MEMBERS], diff --git a/apps/backend/src/api/routes/stripe.controller.ts b/apps/backend/src/api/routes/stripe.controller.ts index 12c6a40a..37aadf24 100644 --- a/apps/backend/src/api/routes/stripe.controller.ts +++ b/apps/backend/src/api/routes/stripe.controller.ts @@ -1,47 +1,19 @@ import { Controller, - Get, - Header, HttpException, - Param, Post, RawBodyRequest, Req, } from '@nestjs/common'; import { StripeService } from '@gitroom/nestjs-libraries/services/stripe.service'; import { ApiTags } from '@nestjs/swagger'; -import { CodesService } from '@gitroom/nestjs-libraries/services/codes.service'; @ApiTags('Stripe') @Controller('/stripe') export class StripeController { constructor( private readonly _stripeService: StripeService, - private readonly _codesService: CodesService ) {} - @Post('/connect') - stripeConnect(@Req() req: RawBodyRequest) { - const event = this._stripeService.validateRequest( - req.rawBody, - // @ts-ignore - req.headers['stripe-signature'], - process.env.STRIPE_SIGNING_KEY_CONNECT - ); - - // Maybe it comes from another stripe webhook - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - if (event?.data?.object?.metadata?.service !== 'gitroom') { - return { ok: true }; - } - - switch (event.type) { - case 'account.updated': - return this._stripeService.updateAccount(event); - default: - return { ok: true }; - } - } @Post('/') stripe(@Req() req: RawBodyRequest) { @@ -66,8 +38,6 @@ export class StripeController { switch (event.type) { case 'invoice.payment_succeeded': return this._stripeService.paymentSucceeded(event); - case 'account.updated': - return this._stripeService.updateAccount(event); case 'customer.subscription.created': return this._stripeService.createSubscription(event); case 'customer.subscription.updated': @@ -81,11 +51,4 @@ export class StripeController { throw new HttpException(e, 500); } } - - @Get('/lifetime-deal-codes/:provider') - @Header('Content-disposition', 'attachment; filename=codes.csv') - @Header('Content-type', 'text/csv') - async getStripeCodes(@Param('provider') providerToken: string) { - return this._codesService.generateCodes(providerToken); - } } diff --git a/apps/backend/src/app.module.ts b/apps/backend/src/app.module.ts index d4f800d4..1a5f89b0 100644 --- a/apps/backend/src/app.module.ts +++ b/apps/backend/src/app.module.ts @@ -3,7 +3,6 @@ import { DatabaseModule } from '@gitroom/nestjs-libraries/database/prisma/databa import { ApiModule } from '@gitroom/backend/api/api.module'; import { APP_GUARD } from '@nestjs/core'; import { PoliciesGuard } from '@gitroom/backend/services/auth/permissions/permissions.guard'; -import { BullMqModule } from '@gitroom/nestjs-libraries/bull-mq-transport-new/bull.mq.module'; import { PublicApiModule } from '@gitroom/backend/public-api/public.api.module'; import { ThrottlerBehindProxyGuard } from '@gitroom/nestjs-libraries/throttler/throttler.provider'; import { ThrottlerModule } from '@nestjs/throttler'; @@ -20,7 +19,6 @@ import { TemporalRegisterMissingSearchAttributesModule } from '@gitroom/nestjs-l @Module({ imports: [ SentryModule.forRoot(), - BullMqModule, DatabaseModule, ApiModule, PublicApiModule, @@ -50,7 +48,6 @@ import { TemporalRegisterMissingSearchAttributesModule } from '@gitroom/nestjs-l }, ], exports: [ - BullMqModule, DatabaseModule, ApiModule, PublicApiModule, diff --git a/apps/backend/src/main.ts b/apps/backend/src/main.ts index d1ee6fb7..3f1c1ae5 100644 --- a/apps/backend/src/main.ts +++ b/apps/backend/src/main.ts @@ -3,6 +3,8 @@ initializeSentry('backend', true); import { loadSwagger } from '@gitroom/helpers/swagger/load.swagger'; import { json } from 'express'; +import { Runtime } from '@temporalio/worker'; +Runtime.install({ shutdownSignals: [] }); process.env.TZ = 'UTC'; @@ -21,7 +23,11 @@ async function start() { rawBody: true, cors: { ...(!process.env.NOT_SECURED ? { credentials: true } : {}), - allowedHeaders: ['Content-Type', 'Authorization', 'x-copilotkit-runtime-client-gql-version'], + allowedHeaders: [ + 'Content-Type', + 'Authorization', + 'x-copilotkit-runtime-client-gql-version', + ], exposedHeaders: [ 'reload', 'onboarding', diff --git a/apps/commands/src/command.module.ts b/apps/commands/src/command.module.ts index 724182b5..6320bd30 100644 --- a/apps/commands/src/command.module.ts +++ b/apps/commands/src/command.module.ts @@ -1,17 +1,15 @@ import { Module } from '@nestjs/common'; import { CommandModule as ExternalCommandModule } from 'nestjs-command'; -import { CheckStars } from './tasks/check.stars'; import { DatabaseModule } from '@gitroom/nestjs-libraries/database/prisma/database.module'; import { RefreshTokens } from './tasks/refresh.tokens'; -import { BullMqModule } from '@gitroom/nestjs-libraries/bull-mq-transport-new/bull.mq.module'; import { ConfigurationTask } from './tasks/configuration'; import { AgentRun } from './tasks/agent.run'; import { AgentModule } from '@gitroom/nestjs-libraries/agent/agent.module'; @Module({ - imports: [ExternalCommandModule, DatabaseModule, BullMqModule, AgentModule], + imports: [ExternalCommandModule, DatabaseModule, AgentModule], controllers: [], - providers: [CheckStars, RefreshTokens, ConfigurationTask, AgentRun], + providers: [RefreshTokens, ConfigurationTask, AgentRun], get exports() { return [...this.imports, ...this.providers]; }, diff --git a/apps/commands/src/tasks/check.stars.ts b/apps/commands/src/tasks/check.stars.ts deleted file mode 100644 index b80ce434..00000000 --- a/apps/commands/src/tasks/check.stars.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { Command, Positional } from 'nestjs-command'; -import { Injectable } from '@nestjs/common'; -import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/client'; - -@Injectable() -export class CheckStars { - constructor(private _workerServiceProducer: BullMqClient) {} - @Command({ - command: 'sync:stars ', - describe: 'Sync stars for a login', - }) - async create( - @Positional({ - name: 'login', - describe: 'login {owner}/{repo}', - type: 'string', - }) - login: string - ) { - this._workerServiceProducer - .emit('check_stars', { payload: { login } }) - .subscribe(); - return true; - } - - @Command({ - command: 'sync:all_stars ', - describe: 'Sync all stars for a login', - }) - async syncAllStars( - @Positional({ - name: 'login', - describe: 'login {owner}/{repo}', - type: 'string', - }) - login: string - ) { - this._workerServiceProducer - .emit('sync_all_stars', { payload: { login } }) - .subscribe(); - return true; - } - - @Command({ - command: 'sync:trending', - describe: 'Sync trending', - }) - async syncTrending() { - this._workerServiceProducer.emit('sync_trending', {}).subscribe(); - return true; - } -} diff --git a/apps/cron/.gitignore b/apps/cron/.gitignore deleted file mode 100644 index 0dff6fb6..00000000 --- a/apps/cron/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -dist/ -node_modules/ -[._]*.s[a-v][a-z] -[._]*.sw[a-p] -[._]s[a-rt-v][a-z] -[._]ss[a-gi-z] -[._]sw[a-p] - diff --git a/apps/cron/nest-cli.json b/apps/cron/nest-cli.json deleted file mode 100644 index 1fcd4a33..00000000 --- a/apps/cron/nest-cli.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/nest-cli", - "collection": "@nestjs/schematics", - "monorepo": false, - "sourceRoot": "src", - "entryFile": "../../dist/cron/apps/cron/src/main", - "language": "ts", - "generateOptions": { - "spec": false - }, - "compilerOptions": { - "manualRestart": true, - "tsConfigPath": "./tsconfig.build.json", - "webpack": false, - "deleteOutDir": true, - "assets": [], - "watchAssets": false, - "plugins": [] - } -} diff --git a/apps/cron/package.json b/apps/cron/package.json deleted file mode 100644 index 6276445d..00000000 --- a/apps/cron/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "postiz-cron", - "version": "1.0.0", - "description": "", - "scripts": { - "dev": "dotenv -e ../../.env -- nest start --watch --entryFile=./apps/cron/src/main", - "build": "cross-env NODE_ENV=production nest build", - "start": "dotenv -e ../../.env -- node --experimental-require-module ./dist/apps/cron/src/main.js", - "pm2": "pm2 start pnpm --name cron -- start" - }, - "keywords": [], - "author": "", - "license": "ISC" -} diff --git a/apps/cron/src/cron.module.ts b/apps/cron/src/cron.module.ts deleted file mode 100644 index 01eb6ed7..00000000 --- a/apps/cron/src/cron.module.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Module } from '@nestjs/common'; -import { ScheduleModule } from '@nestjs/schedule'; -import { DatabaseModule } from '@gitroom/nestjs-libraries/database/prisma/database.module'; -import { BullMqModule } from '@gitroom/nestjs-libraries/bull-mq-transport-new/bull.mq.module'; -import { SentryModule } from '@sentry/nestjs/setup'; -import { FILTER } from '@gitroom/nestjs-libraries/sentry/sentry.exception'; -import { CheckMissingQueues } from '@gitroom/cron/tasks/check.missing.queues'; -import { PostNowPendingQueues } from '@gitroom/cron/tasks/post.now.pending.queues'; - -@Module({ - imports: [ - SentryModule.forRoot(), - DatabaseModule, - ScheduleModule.forRoot(), - BullMqModule, - ], - controllers: [], - providers: [FILTER, CheckMissingQueues, PostNowPendingQueues], -}) -export class CronModule {} diff --git a/apps/cron/src/main.ts b/apps/cron/src/main.ts deleted file mode 100644 index cc2684f9..00000000 --- a/apps/cron/src/main.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { initializeSentry } from '@gitroom/nestjs-libraries/sentry/initialize.sentry'; -initializeSentry('cron'); - -import { NestFactory } from '@nestjs/core'; -import { CronModule } from './cron.module'; - -async function bootstrap() { - // some comment again - await NestFactory.createApplicationContext(CronModule); -} - -bootstrap(); diff --git a/apps/cron/src/tasks/.gitkeep b/apps/cron/src/tasks/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/cron/src/tasks/check.missing.queues.ts b/apps/cron/src/tasks/check.missing.queues.ts deleted file mode 100644 index 0664676c..00000000 --- a/apps/cron/src/tasks/check.missing.queues.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { Cron } from '@nestjs/schedule'; -import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service'; -import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/client'; -import dayjs from 'dayjs'; - -@Injectable() -export class CheckMissingQueues { - constructor( - private _postService: PostsService, - private _workerServiceProducer: BullMqClient - ) {} - @Cron('0 * * * *') - async handleCron() { - const list = await this._postService.searchForMissingThreeHoursPosts(); - const notExists = ( - await Promise.all( - list.map(async (p) => ({ - id: p.id, - publishDate: p.publishDate, - isJob: - ['delayed', 'waiting'].indexOf( - await this._workerServiceProducer - .getQueue('post') - .getJobState(p.id) - ) > -1, - })) - ) - ).filter((p) => !p.isJob); - - - for (const job of notExists) { - this._workerServiceProducer.emit('post', { - id: job.id, - options: { - delay: dayjs(job.publishDate).diff(dayjs(), 'millisecond'), - }, - payload: { - id: job.id, - delay: dayjs(job.publishDate).diff(dayjs(), 'millisecond'), - }, - }); - } - } -} diff --git a/apps/cron/src/tasks/post.now.pending.queues.ts b/apps/cron/src/tasks/post.now.pending.queues.ts deleted file mode 100644 index 69105304..00000000 --- a/apps/cron/src/tasks/post.now.pending.queues.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { Cron } from '@nestjs/schedule'; -import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service'; -import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/client'; - -@Injectable() -export class PostNowPendingQueues { - constructor( - private _postService: PostsService, - private _workerServiceProducer: BullMqClient - ) {} - @Cron('*/16 * * * *') - async handleCron() { - const list = await this._postService.checkPending15minutesBack(); - const notExists = ( - await Promise.all( - list.map(async (p) => ({ - id: p.id, - publishDate: p.publishDate, - isJob: - ['delayed', 'waiting'].indexOf( - await this._workerServiceProducer - .getQueue('post') - .getJobState(p.id) - ) > -1, - })) - ) - ).filter((p) => !p.isJob); - - for (const job of notExists) { - this._workerServiceProducer.emit('post', { - id: job.id, - options: { - delay: 0, - }, - payload: { - id: job.id, - delay: 0, - }, - }); - } - } -} diff --git a/apps/cron/tsconfig.build.json b/apps/cron/tsconfig.build.json deleted file mode 100644 index bf14cec5..00000000 --- a/apps/cron/tsconfig.build.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "extends": "./tsconfig.json", - "exclude": ["node_modules", "test", "dist", "**/*spec.ts"], - "compilerOptions": { - "module": "CommonJS", - "resolveJsonModule": true, - "declaration": true, - "removeComments": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "target": "ES2021", - "sourceMap": true, - "incremental": true, - "skipLibCheck": true, - "strictNullChecks": false, - "noImplicitAny": false, - "strictBindCallApply": false, - "forceConsistentCasingInFileNames": false, - "noFallthroughCasesInSwitch": false, - "outDir": "./dist" - } -} diff --git a/apps/cron/tsconfig.json b/apps/cron/tsconfig.json deleted file mode 100644 index 77fa915a..00000000 --- a/apps/cron/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "module": "commonjs", - "declaration": true, - "removeComments": true, - "allowSyntheticDefaultImports": true, - "noLib": false, - "target": "ES2021", - "sourceMap": true, - "esModuleInterop": true, - } -} diff --git a/apps/frontend/src/components/layout/settings.component.tsx b/apps/frontend/src/components/layout/settings.component.tsx index 90c16e4e..fc1f6a28 100644 --- a/apps/frontend/src/components/layout/settings.component.tsx +++ b/apps/frontend/src/components/layout/settings.component.tsx @@ -77,7 +77,6 @@ export const SettingsPopup: FC<{ return; } toast.show(t('profile_updated', 'Profile updated')); - swr.mutate('/marketplace/account'); close(); }, []); diff --git a/apps/frontend/src/components/marketplace/buyer.seller.tsx b/apps/frontend/src/components/marketplace/buyer.seller.tsx deleted file mode 100644 index 1e910ce7..00000000 --- a/apps/frontend/src/components/marketplace/buyer.seller.tsx +++ /dev/null @@ -1,40 +0,0 @@ -'use client'; - -import { FC } from 'react'; -import { usePathname } from 'next/navigation'; -import clsx from 'clsx'; -import Link from 'next/link'; -import { useT } from '@gitroom/react/translation/get.transation.service.client'; -export const BuyerSeller: FC = () => { - const path = usePathname(); - const t = useT(); - const pathComputed = path === '/marketplace' ? '/marketplace/seller' : path; - return ( -
-
-
- -1 && - 'bg-forth text-white' - )} - > - {t('seller', 'Seller')} - - -1 && - 'bg-forth text-white' - )} - > - {t('buyer', 'Buyer')} - -
-
-
- ); -}; diff --git a/apps/frontend/src/components/marketplace/buyer.tsx b/apps/frontend/src/components/marketplace/buyer.tsx deleted file mode 100644 index 064c2faf..00000000 --- a/apps/frontend/src/components/marketplace/buyer.tsx +++ /dev/null @@ -1,568 +0,0 @@ -'use client'; - -import React, { - FC, - Fragment, - useCallback, - useEffect, - useMemo, - useRef, - useState, -} from 'react'; -import { Checkbox } from '@gitroom/react/form/checkbox'; -import { useRouter, useSearchParams } from 'next/navigation'; -import clsx from 'clsx'; -import { Button } from '@gitroom/react/form/button'; -import { - allTagsOptions, - tagsList, -} from '@gitroom/nestjs-libraries/database/prisma/marketplace/tags.list'; -import { capitalize, chunk, fill } from 'lodash'; -import useSWR from 'swr'; -import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; -import { useModals } from '@gitroom/frontend/components/layout/new-modal'; -import { TopTitle } from '@gitroom/frontend/components/launches/helpers/top.title.component'; -import { Textarea } from '@gitroom/react/form/textarea'; -import { FormProvider, SubmitHandler, useForm } from 'react-hook-form'; -import { classValidatorResolver } from '@hookform/resolvers/class-validator'; -import { NewConversationDto } from '@gitroom/nestjs-libraries/dtos/marketplace/new.conversation.dto'; -import { OrderList } from '@gitroom/frontend/components/marketplace/order.list'; -import { useT } from '@gitroom/react/translation/get.transation.service.client'; -export interface Root { - list: List[]; - count: number; -} -export interface List { - id: string; - name: any; - bio: string; - audience: number; - picture: { - id: string; - path: string; - }; - organizations: Organization[]; - items: Item[]; -} -export interface Organization { - organization: Organization2; -} -export interface Organization2 { - Integration: Integration[]; -} -export interface Integration { - providerIdentifier: string; -} -export interface Item { - key: string; -} -export const LabelCheckbox: FC<{ - label: string; - name: string; - value: string; - checked: boolean; - onChange: (value: string, status: boolean) => void; -}> = (props) => { - const { label, name, value, checked, onChange } = props; - const ref = useRef(null); - const [innerCheck, setInnerCheck] = useState(checked); - const change = useCallback(() => { - setInnerCheck(!innerCheck); - onChange(value, !innerCheck); - }, [innerCheck]); - return ( -
- - -
- ); -}; -const Pagination: FC<{ - results: number; -}> = (props) => { - const { results } = props; - const router = useRouter(); - const search = useSearchParams(); - const page = +(parseInt(search.get('page')!) || 1) - 1; - const t = useT(); - const from = page * 8; - const to = (page + 1) * 8; - const pagesArray = useMemo(() => { - return Array.from( - { - length: Math.ceil(results / 8), - }, - (_, i) => i + 1 - ); - }, [results]); - const changePage = useCallback( - (newPage: number) => () => { - const params = new URLSearchParams(window.location.search); - params.set('page', String(newPage)); - router.replace('?' + params.toString(), { - scroll: true, - }); - }, - [page] - ); - if (results < 8) { - return null; - } - return ( -
-
- {t('showing', 'Showing')} - {from + 1} - {t('to', 'to')} - {to > results ? results : to} - {t('from', 'from')} - {results} - {t('results', 'Results')} -
-
- {page > 0 && ( -
- - - - - - - - - - -
- )} - {pagesArray.map((p) => ( -
- {p} -
- ))} - {page + 1 < pagesArray[pagesArray.length - 1] && ( - - - - )} -
-
- ); -}; -export const Options: FC<{ - title: string; - options: Array<{ - key: string; - value: string; - }>; - onChange?: (key: string, value: boolean) => void; - preSelected?: string[]; - rows?: number; - search: boolean; -}> = (props) => { - const { title, onChange, search, preSelected } = props; - const query = 'services'; - const [selected, setPreSelected] = useState( - preSelected?.slice(0) || [] - ); - const rows = props.rows || 1; - const optionsGroupList = chunk( - props.options, - Math.ceil(props.options.length / rows) - ); - const optionsGroup = - optionsGroupList.length < rows - ? [ - ...optionsGroupList, - ...fill(Array(rows - optionsGroupList.length), []), - ] - : optionsGroupList; - const router = useRouter(); - const searchParams = (useSearchParams().get(query) || '')?.split(',') || []; - const change = (value: string, state: boolean) => { - if (onChange) { - onChange(value, state); - } - if (!search) { - return; - } - const getAll = new URLSearchParams(window.location.search).get(query); - const splitAll = (getAll?.split(',') || []).filter((f) => f); - if (state) { - splitAll?.push(value); - } else { - splitAll?.splice(splitAll.indexOf(value), 1); - } - const params = new URLSearchParams(window.location.search); - if (!splitAll?.length) { - params.delete(query); - } else { - params.set(query, splitAll?.join(',') || ''); - } - router.replace('?' + params.toString()); - return params.toString(); - }; - return ( - <> -
- {title} -
-
- {optionsGroup.map((options, key) => ( -
- {options.map((option) => ( -
- -1 || - searchParams.indexOf(option.key) > -1 - } - name={query} - onChange={change} - /> -
- ))} -
- ))} -
- - ); -}; -export const RequestService: FC<{ - toId: string; - name: string; -}> = (props) => { - const { toId, name } = props; - const router = useRouter(); - const fetch = useFetch(); - const modal = useModals(); - const resolver = useMemo(() => { - return classValidatorResolver(NewConversationDto); - }, []); - const form = useForm({ - resolver, - values: { - to: toId, - message: '', - }, - }); - const close = useCallback(() => { - return modal.closeAll(); - }, []); - - const t = useT(); - - const createConversation: SubmitHandler = useCallback( - async (data) => { - const { id } = await ( - await fetch('/marketplace/conversation', { - method: 'POST', - body: JSON.stringify(data), - }) - ).json(); - close(); - router.push(`/messages/${id}`); - }, - [] - ); - return ( -
- -
- -
- -