Commit 51d15992 authored by Дмитрий Малюгин's avatar Дмитрий Малюгин 🕓
Browse files

refactor code in process

parent 6bdddffb
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -24,17 +24,17 @@ model User {
  middle_name   String?
  last_name     String?
  settings      Json?
  pages_uuid    Json?
  sheets_uuid    Json?
}

model Page {
model Sheet {
  user_uuid             String
  page_uuid             String @id @default(uuid())
  page_title            String
  page_icon             String
  page_navigation_order String
  sheet_uuid             String @id @default(uuid())
  sheet_title            String
  sheet_icon             String
  sheet_navigation_order String
  background_path       String? @db.Text
  page_entities         Json?
  sheet_entities         Json?
}

model Entity {
+3 −3
Original line number Diff line number Diff line
import EntitiesService from '../services/entitiesService';
import { IBodyPageUuid, IChangeEntitiesOrder, IWSRequest } from '../interface/requests';
import { IBodySheetUuid, IChangeEntitiesOrder, IWSRequest } from '../interface/requests';
import { IEntity } from '../interface/database';

class EntitiesController {
@@ -17,9 +17,9 @@ class EntitiesController {
      console.log(error);
    }
  }
  async getEntities(req: IWSRequest<'getEntities', IBodyPageUuid>) {
  async getEntities(req: IWSRequest<'getEntities', IBodySheetUuid>) {
    try {
      return await EntitiesService.getEntities(req.body.page_uuid);
      return await EntitiesService.getEntities(req.body.sheet_uuid);
    } catch (error) {
      console.log(error);
      return error;
+65 −0
Original line number Diff line number Diff line
import PagesService from '../services/pagesService';
import { IEditPageBackground, IBodyPageUuid, IWSRequest, IBodyPage } from '../interface/requests';
import SheetsService from '../services/sheetsService';
import {
  IEditSheetBackground,
  IBodySheetUuid,
  IWSRequest,
  IBodySheet
} from '../interface/requests';

class PagesController {
  async createPage(req: IWSRequest<'createPage', IBodyPage>) {
class SheetsController {
  async createSheet(req: IWSRequest<'createSheet', IBodySheet>) {
    try {
      return await PagesService.createPage(req.body);
      return await SheetsService.createSheet(req.body);
    } catch (error) {
      console.log(error);
      return error;
    }
  }
  async getPage(req: IWSRequest<'getPage', IBodyPageUuid>) {
  async getSheet(req: IWSRequest<'getSheet', IBodySheetUuid>) {
    try {
      return await PagesService.getPage(req.body);
      return await SheetsService.getSheet(req.body);
    } catch (error) {
      console.log(error);
      return error;
    }
  }
  async getPageBackground(req: IWSRequest<'deletePageBackground', IBodyPageUuid>) {
  async getSheetBackground(req: IWSRequest<'deleteSheetBackground', IBodySheetUuid>) {
    try {
      return await PagesService.getPageBackground(req.body.page_uuid);
      return await SheetsService.getSheetBackground(req.body.sheet_uuid);
    } catch (error) {
      console.log(error);
      return error;
    }
  }
  async editPage(req: IWSRequest<'editPage', IBodyPage>) {
  async editSheet(req: IWSRequest<'editSheet', IBodySheet>) {
    try {
      return await PagesService.editPage(req.body);
      return await SheetsService.editSheet(req.body);
    } catch (error) {
      console.log(error);
      return error;
    }
  }
  async editPageBackground(req: IWSRequest<'editPageBackground', IEditPageBackground>) {
  async editSheetBackground(req: IWSRequest<'editSheetBackground', IEditSheetBackground>) {
    try {
      return await PagesService.editPageBackground(req.body);
      return await SheetsService.editSheetBackground(req.body);
    } catch (error) {
      console.log(error);
    }
  }
  async deletePage(req: IWSRequest<'deletePage', IBodyPage>) {
  async deleteSheet(req: IWSRequest<'deleteSheet', IBodySheet>) {
    try {
      return PagesService.deletePage(req.body);
      return SheetsService.deleteSheet(req.body);
    } catch (error) {
      console.log(error);
    }
  }
  async deletePageBackground(req: IWSRequest<'deletePageBackground', IBodyPageUuid>) {
  async deleteSheetBackground(req: IWSRequest<'deleteSheetBackground', IBodySheetUuid>) {
    try {
      await PagesService.deletePageBackground(req.body.page_uuid);
      await SheetsService.deleteSheetBackground(req.body.sheet_uuid);
    } catch (error) {
      console.log(error);
    }
  }
}

export default new PagesController();
export default new SheetsController();
+2 −2
Original line number Diff line number Diff line
export interface IPageEntity {
export interface ISheetEntity {
  entity_uuid: string;
  entity_type: 'divider' | 'paragraph' | 'image' | 'table';
}
export interface IEntity {
  page_uuid?: string;
  sheet_uuid?: string;
  entity_uuid: string;
  entity_type: 'divider' | 'paragraph' | 'image' | 'table';
  entity_order?: number;
+10 −10
Original line number Diff line number Diff line
@@ -2,13 +2,13 @@ export interface IWSRequest<T, B> {
  event: T;
  body: B;
}
export interface IBodyPage {
export interface IBodySheet {
  user_uuid: string;
  page_title: string;
  page_navigation_order?: string;
  page_icon?: string;
  page_uuid?: string;
  page_entities?: string;
  sheet_title: string;
  sheet_navigation_order?: string;
  sheet_icon?: string;
  sheet_uuid?: string;
  sheet_entities?: string;
}
export interface IBodyUser {
  nick_name: string;
@@ -19,11 +19,11 @@ export interface IBodyUser {
  last_name?: string;
  user_uuid?: string;
}
export interface IBodyPageUuid {
  page_uuid: string;
export interface IBodySheetUuid {
  sheet_uuid: string;
}
export interface IEditPageBackground {
  page_uuid: string;
export interface IEditSheetBackground {
  sheet_uuid: string;
  background_url: string;
}
interface IEntityUuidAndOrder {
Loading