Skip to content

Commit 9ec432b

Browse files
configuration gateway is implemented
1 parent 470da79 commit 9ec432b

File tree

3 files changed

+68
-7
lines changed

3 files changed

+68
-7
lines changed

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"skipFiles": [
12+
"<node_internals>/**"
13+
],
14+
"program": "${workspaceFolder}/src/main.ts",
15+
"preLaunchTask": "tsc: build - tsconfig.json",
16+
"outFiles": [
17+
"${workspaceFolder}/dist/**/*.js"
18+
]
19+
}
20+
]
21+
}

src/configuration/configuration.gateway.ts

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class ConfigurationGateway {
1212
@SubscribeMessage('panel.configurations.storefronts.get')
1313
async getStorefrontConfigsForPanel() {
1414
const configs = await this.configurationService.getAll(PlatformTypes.Storefront);
15-
return { event: `panel.configurations.storefronts`, data: configs };
15+
return { event: 'panel.configurations.storefronts', data: configs };
1616
}
1717

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

2424
@SubscribeMessage('panel.configurations.storefront.add')
25-
async addStorefrontConfigs(@MessageBody() body: { configurations: Configuration[], name: string }) {
25+
async addStorefrontConfigs(@MessageBody() body: { configurations: Configuration, name: string }) {
2626
if (!body.configurations) return null;
27-
const configs = await this.configurationService.add(PlatformTypes.Storefront, body.name, body.configurations);
28-
this.server.emit(`panel.configurations.storefront.${body.name}`, configs);
27+
await this.configurationService.add(PlatformTypes.Storefront, body.name, body.configurations);
28+
this.server.emit('panel.configurations.storefronts', await this.configurationService.getAll(PlatformTypes.Storefront));
29+
this.server.emit(`configurations.storefront.update`, body.configurations);
30+
}
31+
32+
@SubscribeMessage('panel.configurations.gateway.add')
33+
async addGatewayConfigs(@MessageBody() body: { configurations: Configuration, name: string }) {
34+
if (!body.configurations) return null;
35+
await this.configurationService.add(PlatformTypes.Gateway, body.name, body.configurations);
36+
this.server.emit('panel.configurations.gateways', await this.configurationService.getAll(PlatformTypes.Gateway));
37+
this.server.emit(`configurations.gateway.update`, body.configurations);
38+
}
39+
40+
@SubscribeMessage('panel.configurations.storefront.update')
41+
async updateStorefrontConfigs(@MessageBody() body: { configurations: Configuration, name: string }) {
42+
if (!body.configurations) return null;
43+
await this.configurationService.update(PlatformTypes.Storefront, body.name, body.configurations);
44+
this.server.emit('panel.configurations.storefronts', await this.configurationService.getAll(PlatformTypes.Storefront));
45+
this.server.emit(`configurations.storefront.update`, body.configurations);
46+
}
47+
48+
@SubscribeMessage('panel.configurations.gateway.update')
49+
async updateGatewayConfigs(@MessageBody() body: { configurations: Configuration, name: string }) {
50+
if (!body.configurations) return null;
51+
await this.configurationService.update(PlatformTypes.Gateway, body.name, body.configurations);
52+
this.server.emit('panel.configurations.gateways', await this.configurationService.getAll(PlatformTypes.Gateway));
53+
this.server.emit(`configurations.gateway.update`, body.configurations);
54+
}
55+
56+
@SubscribeMessage('panel.configurations.storefront.delete')
57+
async deleteStorefrontConfigs(@MessageBody() body: { name: string }) {
58+
if (!body.name) return null;
59+
await this.configurationService.delete(PlatformTypes.Storefront, body.name);
60+
this.server.emit('panel.configurations.storefronts', await this.configurationService.getAll(PlatformTypes.Storefront));
61+
this.server.emit(`configurations.storefront.delete`, body.name);
62+
}
63+
64+
@SubscribeMessage('panel.configurations.gateway.delete')
65+
async deleteGatewayConfigs(@MessageBody() body: { name: string }) {
66+
if (!body.name) return null;
67+
await this.configurationService.delete(PlatformTypes.Gateway, body.name);
68+
this.server.emit('panel.configurations.gateways', await this.configurationService.getAll(PlatformTypes.Gateway));
69+
this.server.emit(`configurations.gateway.delete`, body.name);
2970
}
3071

3172
@SubscribeMessage('configurations.storefront.get')

src/configuration/configuration.service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { PlatformTypes } from '../enums';
88
export class ConfigurationService {
99
constructor(private readonly couchbaseService: CouchbaseService) { }
1010

11-
add(type: PlatformTypes, name: string, configuration: Configuration[]) {
11+
add(type: PlatformTypes, name: string, configuration: Configuration) {
1212
return new Promise((resolve, reject) => {
1313
this.couchbaseService.getBucket().insert(`configuration_${type}_${name}`, {configuration, type: `configuration_${type}`}, (err, data) => {
1414
if (err) return reject(null);
@@ -39,7 +39,6 @@ export class ConfigurationService {
3939
return new Promise((resolve, reject) => {
4040
this.couchbaseService.getBucket().get(`configuration_${type}_${name}`, (err, data) => {
4141
if (err) return reject(null);
42-
console.log("get data: ", data);
4342
resolve(data.map((g) => g.value));
4443
});
4544
});
@@ -52,7 +51,7 @@ export class ConfigurationService {
5251
.stale(ViewQuery.Update.BEFORE);
5352
this.couchbaseService.getBucket().query(query, (err, data) => {
5453
if (err) return reject(null);
55-
resolve(data.map((g) => g.value));
54+
resolve(data.map((g) => g.value?.configuration));
5655
});
5756
});
5857
}

0 commit comments

Comments
 (0)