apps.resolver.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { Arg, Authorized, Mutation, Query, Resolver } from 'type-graphql';
  2. import AppsService from './apps.service';
  3. import { AppConfig, AppInputType, ListAppsResonse } from './apps.types';
  4. import App from './app.entity';
  5. @Resolver()
  6. export default class AppsResolver {
  7. @Query(() => ListAppsResonse)
  8. listAppsInfo(): Promise<ListAppsResonse> {
  9. return AppsService.listApps();
  10. }
  11. @Query(() => AppConfig)
  12. getAppInfo(@Arg('id', () => String) appId: string): Promise<AppConfig> {
  13. return AppsService.getAppInfo(appId);
  14. }
  15. @Authorized()
  16. @Query(() => [App])
  17. async installedApps(): Promise<App[]> {
  18. return App.find();
  19. }
  20. @Authorized()
  21. @Mutation(() => App)
  22. async installApp(@Arg('input', () => AppInputType) input: AppInputType): Promise<App> {
  23. const { id, form } = input;
  24. return AppsService.installApp(id, form);
  25. }
  26. @Authorized()
  27. @Mutation(() => App)
  28. async startApp(@Arg('id', () => String) id: string): Promise<App> {
  29. return AppsService.startApp(id);
  30. }
  31. @Authorized()
  32. @Mutation(() => App)
  33. async stopApp(@Arg('id', () => String) id: string): Promise<App> {
  34. return AppsService.stopApp(id);
  35. }
  36. @Authorized()
  37. @Mutation(() => App)
  38. async uninstallApp(@Arg('id', () => String) id: string): Promise<boolean> {
  39. return AppsService.uninstallApp(id);
  40. }
  41. @Authorized()
  42. @Mutation(() => App)
  43. async updateAppConfig(@Arg('input', () => AppInputType) input: AppInputType): Promise<App> {
  44. const { id, form } = input;
  45. return AppsService.updateAppConfig(id, form);
  46. }
  47. }