Skip to content

Commit

Permalink
fix(storage): migrate non admin routes
Browse files Browse the repository at this point in the history
  • Loading branch information
sdimitris committed Jan 10, 2022
1 parent ec4f86e commit 7e2291c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions modules/storage/src/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { status } from '@grpc/grpc-js';
import * as path from 'path';
import { FileHandlers } from './handlers/file';
import { FileRoutes } from './routes/router';
import { StorageRoutes } from './routes/router';
import { AdminRoutes } from './admin/admin';
import { migrateFoldersToContainers } from './migrations/container.migrations';
import * as models from './models';
Expand All @@ -19,6 +19,7 @@ export class StorageModule extends ConduitServiceModule {
private _fileHandlers: FileHandlers;
private _routes: any[];
private isRunning: boolean = false;
private _router: StorageRoutes;

get routes() {
return this._routes;
Expand Down Expand Up @@ -164,9 +165,10 @@ export class StorageModule extends ConduitServiceModule {
azure,
});
this._fileHandlers = new FileHandlers(this.grpcSdk, this.storageProvider);
new FileRoutes(this.grpcServer, this.grpcSdk, this._fileHandlers);
this._router = new StorageRoutes(this.grpcServer, this.grpcSdk, this._fileHandlers);
new AdminRoutes(this.grpcServer, this.grpcSdk, this._fileHandlers);
this._fileHandlers.updateProvider(this.storageProvider);
await this._router.registerRoutes();
}

private registerSchemas() {
Expand Down
14 changes: 8 additions & 6 deletions modules/storage/src/routes/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@ import ConduitGrpcSdk, {
TYPE,
} from '@quintessential-sft/conduit-grpc-sdk';

export class FileRoutes {
export class StorageRoutes {
constructor(
readonly server: GrpcServer,
private readonly grpcSdk: ConduitGrpcSdk,
private readonly fileHandlers: FileHandlers
) {
) {}
async registerRoutes() {
let activeRoutes = await this.getRegisteredRoutes();
this.grpcSdk.router
.registerRouter(server, this.registeredRoutes, {
.registerRouterAsync(this.server, activeRoutes, {
createFile: this.fileHandlers.createFile.bind(this.fileHandlers),
deleteFile: this.fileHandlers.deleteFile.bind(this.fileHandlers),
getFile: this.fileHandlers.getFile.bind(this.fileHandlers),
getFileData: this.fileHandlers.getFileData.bind(this.fileHandlers),
updateFile: this.fileHandlers.updateFile.bind(this.fileHandlers),
getFileUrl: this.fileHandlers.getFileUrl.bind(this.fileHandlers),
deleteFile: this.fileHandlers.deleteFile.bind(this.fileHandlers),
updateFile: this.fileHandlers.updateFile.bind(this.fileHandlers),
})
.catch((err: Error) => {
console.log('Failed to register routes for module');
console.log(err);
});
}

get registeredRoutes(): any[] {
async getRegisteredRoutes(): Promise<any[]> {
let routesArray: any = [];
routesArray.push(
constructRoute(
Expand Down

0 comments on commit 7e2291c

Please sign in to comment.