Skip to content

Commit

Permalink
configuration gateway is implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetsefabalik committed Nov 25, 2019
1 parent 470da79 commit 9ec432b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/src/main.ts",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
}
]
}
49 changes: 45 additions & 4 deletions src/configuration/configuration.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ConfigurationGateway {
@SubscribeMessage('panel.configurations.storefronts.get')
async getStorefrontConfigsForPanel() {
const configs = await this.configurationService.getAll(PlatformTypes.Storefront);
return { event: `panel.configurations.storefronts`, data: configs };
return { event: 'panel.configurations.storefronts', data: configs };
}

@SubscribeMessage('panel.configurations.gateways.get')
Expand All @@ -22,10 +22,51 @@ export class ConfigurationGateway {
}

@SubscribeMessage('panel.configurations.storefront.add')
async addStorefrontConfigs(@MessageBody() body: { configurations: Configuration[], name: string }) {
async addStorefrontConfigs(@MessageBody() body: { configurations: Configuration, name: string }) {
if (!body.configurations) return null;
const configs = await this.configurationService.add(PlatformTypes.Storefront, body.name, body.configurations);
this.server.emit(`panel.configurations.storefront.${body.name}`, configs);
await this.configurationService.add(PlatformTypes.Storefront, body.name, body.configurations);
this.server.emit('panel.configurations.storefronts', await this.configurationService.getAll(PlatformTypes.Storefront));
this.server.emit(`configurations.storefront.update`, body.configurations);
}

@SubscribeMessage('panel.configurations.gateway.add')
async addGatewayConfigs(@MessageBody() body: { configurations: Configuration, name: string }) {
if (!body.configurations) return null;
await this.configurationService.add(PlatformTypes.Gateway, body.name, body.configurations);
this.server.emit('panel.configurations.gateways', await this.configurationService.getAll(PlatformTypes.Gateway));
this.server.emit(`configurations.gateway.update`, body.configurations);
}

@SubscribeMessage('panel.configurations.storefront.update')
async updateStorefrontConfigs(@MessageBody() body: { configurations: Configuration, name: string }) {
if (!body.configurations) return null;
await this.configurationService.update(PlatformTypes.Storefront, body.name, body.configurations);
this.server.emit('panel.configurations.storefronts', await this.configurationService.getAll(PlatformTypes.Storefront));
this.server.emit(`configurations.storefront.update`, body.configurations);
}

@SubscribeMessage('panel.configurations.gateway.update')
async updateGatewayConfigs(@MessageBody() body: { configurations: Configuration, name: string }) {
if (!body.configurations) return null;
await this.configurationService.update(PlatformTypes.Gateway, body.name, body.configurations);
this.server.emit('panel.configurations.gateways', await this.configurationService.getAll(PlatformTypes.Gateway));
this.server.emit(`configurations.gateway.update`, body.configurations);
}

@SubscribeMessage('panel.configurations.storefront.delete')
async deleteStorefrontConfigs(@MessageBody() body: { name: string }) {
if (!body.name) return null;
await this.configurationService.delete(PlatformTypes.Storefront, body.name);
this.server.emit('panel.configurations.storefronts', await this.configurationService.getAll(PlatformTypes.Storefront));
this.server.emit(`configurations.storefront.delete`, body.name);
}

@SubscribeMessage('panel.configurations.gateway.delete')
async deleteGatewayConfigs(@MessageBody() body: { name: string }) {
if (!body.name) return null;
await this.configurationService.delete(PlatformTypes.Gateway, body.name);
this.server.emit('panel.configurations.gateways', await this.configurationService.getAll(PlatformTypes.Gateway));
this.server.emit(`configurations.gateway.delete`, body.name);
}

@SubscribeMessage('configurations.storefront.get')
Expand Down
5 changes: 2 additions & 3 deletions src/configuration/configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PlatformTypes } from '../enums';
export class ConfigurationService {
constructor(private readonly couchbaseService: CouchbaseService) { }

add(type: PlatformTypes, name: string, configuration: Configuration[]) {
add(type: PlatformTypes, name: string, configuration: Configuration) {
return new Promise((resolve, reject) => {
this.couchbaseService.getBucket().insert(`configuration_${type}_${name}`, {configuration, type: `configuration_${type}`}, (err, data) => {
if (err) return reject(null);
Expand Down Expand Up @@ -39,7 +39,6 @@ export class ConfigurationService {
return new Promise((resolve, reject) => {
this.couchbaseService.getBucket().get(`configuration_${type}_${name}`, (err, data) => {
if (err) return reject(null);
console.log("get data: ", data);
resolve(data.map((g) => g.value));
});
});
Expand All @@ -52,7 +51,7 @@ export class ConfigurationService {
.stale(ViewQuery.Update.BEFORE);
this.couchbaseService.getBucket().query(query, (err, data) => {
if (err) return reject(null);
resolve(data.map((g) => g.value));
resolve(data.map((g) => g.value?.configuration));
});
});
}
Expand Down

0 comments on commit 9ec432b

Please sign in to comment.