Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (Job) {
// Attach job submission to Kafka
if ('queue' in config && config.queue === 'kafka') {
// var options = {
// connectionString: 'localhost:2181/'
// };
var dataSource = new DataSource('kafka', options);
Job.attachTo(dataSource);
}
Job.observe('before save', (ctx, next) => {
// email job initiator should always be the person running the job request
// therefore override this field both for users and functional accounts
if (ctx.instance) {
ctx.instance.emailJobInitiator = ctx.options.currentUserEmail;
if (ctx.isNewInstance) {
ctx.instance.jobStatusMessage = "jobSubmitted"
}
}
next()
});
Job.observe('after save', (ctx, next) => {
global.getDataSource = global.getSchema = function(customConfig) {
var db = new DataSource(require('../'), customConfig || config);
db.log = function(a) {
console.log(a);
};
var originalConnector = _.clone(db.connector);
var overrideConnector = {};
overrideConnector.save = function(model, data, options, cb) {
if (!global.IMPORTED_TEST) {
return originalConnector.save(model, data, options, cb);
} else {
var self = this;
var idName = self.idName(model);
var id = data[idName];
var mo = self.selectModel(model);
data[idName] = id.toString();
global.getDataSource = global.getSchema = customConfig => {
const db = new DataSource(lib, customConfig || config);
db.log = a => {
console.log(a);
};
return db;
};
global.getDataSource = global.getSchema = function(customConfig) {
const db = new DataSource(require('../'), customConfig || config);
db.log = function(a) {
console.log(a);
};
return db;
};
function givenProductRepository() {
const db = new DataSource({
connector: 'memory',
});
repo = new ProductRepository(db);
}
});
const getDS = function(myconfig) {
const db = new DataSource(mssqlConnector, myconfig);
return db;
};
})
id: number;
@property({type: 'string'})
name: string;
@property.array(Role)
roles: Role[];
@property()
address: Address;
}
const userRepo = new DefaultCrudRepository(
User,
new DataSource({connector: 'memory'}),
);
const user = {
id: 1,
name: 'foo',
roles: [{name: 'admin'}, {name: 'user'}],
address: {street: 'backstreet'},
};
const created = await userRepo.create(user);
const stored = await userRepo.findById(created.id);
expect(stored).to.containDeep(user);
});
DefaultCrudRepository
>(injection.bindingKey);
/**
* discussion point: use a fake DataSource instance so that we can get back
* the source model possible alternatives we considered:
* - use context to resolve an instance of the source repository and thus a
* source model (results in circular dependency between related
* repositories)
* - change UX so that users pass in the source model manually
* (inconvenient)
* - enforce binding of models to application context, so that it can be
* retrieved
*/
const fakeDs = new DataSource();
const sourceModel = new injection.metadata!.sourceRepo(fakeDs).entityClass;
return getConstrainedRepositoryFunction(sourceModel, tRepo);
}
}