Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { PoSchemaDefinitionService } from './../po-schema/po-schema-definition/po-schema-definition.service';
import { PoSchemaService } from './../po-schema/po-schema.service';
import { PoSchemaUtil } from './../po-schema/po-schema-util/po-schema-util.model';
import { PoSyncConfig } from '../po-sync/interfaces/po-sync-config.interface';
import { PoSyncResponse } from '../po-sync/interfaces/po-sync-response.interface';
import { PoSyncSchema } from './../po-sync/interfaces/po-sync-schema.interface';
@Injectable()
export class PoEventSourcingService {
static readonly event_sourcing_name: string = 'EventSourcing';
private static readonly VALID_HTTP_STATUS_CODES = [
HttpStatus.OK, // 200
HttpStatus.CREATED, // 201
HttpStatus.ACCEPTED, // 202
HttpStatus.NON_AUTHORITATIVE_INFORMATION, // 203
HttpStatus.NO_CONTENT, // 204
HttpStatus.RESET_CONTENT, // 205
HttpStatus.PARTIAL_CONTENT, // 206
HttpStatus.MULTI_STATUS, // 207
];
config: PoSyncConfig;
stoppedQueueEventSourcing: boolean = false;
private emitter: any;
private eventSub: Observable;
private responseSubject = new Subject();
private schemasSyncConfig = {};
switch (statusCode) {
case HttpStatus.OK:
reply = {
statusCode: altStatusCode || HttpStatus.OK,
code: altCode || HttpStatus.getStatusText(HttpStatus.OK),
value: {
state: 'Succeeded',
description: 'Operation was successful.'
}
};
break;
case HttpStatus.ACCEPTED:
reply = {
statusCode: altStatusCode || HttpStatus.ACCEPTED,
code: altCode || HttpStatus.getStatusText(HttpStatus.ACCEPTED),
value: {
state: 'Succeeded',
description: 'Operation was successful.'
}
};
break;
case HttpStatus.INTERNAL_SERVER_ERROR:
reply = {
statusCode: altStatusCode || HttpStatus.INTERNAL_SERVER_ERROR,
code: altCode || HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR),
value: {
state: 'Failed',
description: 'Operation failed. Check the log for details.'
}
};
var Reply = function(statusCode, altStatusCode, altCode) {
var reply = {};
switch (statusCode) {
case HttpStatus.OK:
reply = {
statusCode: altStatusCode || HttpStatus.OK,
code: altCode || HttpStatus.getStatusText(HttpStatus.OK),
value: {
state: 'Succeeded',
description: 'Operation was successful.'
}
};
break;
case HttpStatus.ACCEPTED:
reply = {
statusCode: altStatusCode || HttpStatus.ACCEPTED,
code: altCode || HttpStatus.getStatusText(HttpStatus.ACCEPTED),
value: {
state: 'Succeeded',
description: 'Operation was successful.'
}
};
break;
case HttpStatus.INTERNAL_SERVER_ERROR:
reply = {
statusCode: altStatusCode || HttpStatus.INTERNAL_SERVER_ERROR,
code: altCode || HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR),
value: {
state: 'Failed',
cp.deprovision(redisClient, function (err, result) {
if (err) {
common.handleServiceError(err, next);
} else {
next(null, Reply(HttpStatus.ACCEPTED), result);
}
});
};
cp.provision(docDbClient, function(err, result) {
if (err) {
common.handleServiceError(err, next);
} else {
next(null, Reply(HttpStatus.ACCEPTED), result);
}
});
};
router.post('/slack', handleRejections(async (req, res) => {
const token = req.body.token
if (!token) return res.sendStatus(statusCode.BAD_REQUEST)
const message = req.body.message
if (!message) return res.sendStatus(statusCode.BAD_REQUEST)
res.sendStatus(statusCode.ACCEPTED)
const dsm = req.dashboardSocketManager
const dashboards = await Dashboard.find({ webhookTokens: [token] })
dashboards.forEach(dashboard => {
dsm.sendDashboardNotification(message, dashboard.id)
})
}))
export function accepted(arg1: T | string | Wrapper, arg2?: string): T {
return answer(HTTP.ACCEPTED, arg1, arg2);
}
utils.delNamespace(azure_config, function(err) {
if (err) {
common.handleServiceError(err, next);
} else {
var reply = {
statusCode: HttpStatus.ACCEPTED,
code: HttpStatus.getStatusText(HttpStatus.ACCEPTED),
value: {}
};
next(null, reply, provisioningResult);
}
});
};
utils.delNamespace(azure_config, function(err) {
if (err) {
common.handleServiceError(err, next);
} else {
var reply = {
statusCode: HttpStatus.ACCEPTED,
code: HttpStatus.getStatusText(HttpStatus.ACCEPTED),
value: {}
};
next(null, reply, provisioningResult);
}
});
};
msRestRequest.PUT(that.failoverGroupUrl, headers, body, API_VERSIONS.SQLFG, function (err, res, body) {
if (err) {
log.info('client: createFailoverGroup: err %j', err);
return callback(err, null);
}
common.logHttpResponse(res, 'client - createFailoverGroup', true);
if (res.statusCode == HttpStatus.ACCEPTED) {
callback(null, res['headers']['azure-asyncoperation']);
} else if (res.statusCode == HttpStatus.OK || res.statusCode == HttpStatus.NO_CONTENT) {
callback(null);
} else {
return common.formatErrorFromRes(res, callback);
}
});