Skip to content

Instantly share code, notes, and snippets.

@royib
royib / DatabaseServices.js
Created October 15, 2019 11:09
Node Clean Architecture – DatabaseServices Contract
class DatabaseServices {
constructor() {
this.studentRepository = null;
}
initDatabase() {
return new Promise((resolve, reject) => {
reject(new Error('not implemented'));
});
@royib
royib / CrmServices.js
Created October 15, 2019 11:15
Node Clean Architecture – CrmServices Contract
module.exports = class CrmServices {
notify(studentDetails) {
return new Promise((resolve, reject) => {
reject(new Error('not implemented'));
});
}
};
@royib
royib / StudentRepository.js
Last active October 16, 2019 08:29
Node Clean Architecture – StudentRepository Contract
module.exports = class StudentRepository {
constructor() { }
add(studentInstance) {
return new Promise((resolve, reject) => {
reject(new Error('not implemented'));
});
}
update(studentInstance) {
@royib
royib / StudentController.js
Created October 16, 2019 11:28
Node Clean Architecture -Controllers and Presenters - StudentController.js
const AddStudent = require('../../application/use_cases/AddStudent');
const GetAllStudents = require('../../application/use_cases/GetAllStudents');
const GetStudent = require('../../application/use_cases/GetStudent');
const AddEnrollment = require('../../application/use_cases/AddEnrollment');
module.exports = (dependecies) => {
const { studentRepository } = dependecies.DatabaseService;
const { CrmServices } = dependecies;
@royib
royib / InMemoryStudentRepository.js
Created October 16, 2019 12:28
Node Clean Architecture - Frameworks - InMemoryStudentRepository.js
const StudentRepository = require('../../../application/contracts/StudentRepository');
module.exports = class InMemoryStudentRepository extends StudentRepository {
constructor() {
super();
this.students = [];
this.currentId = 1;
}
@royib
royib / projectDependencies.js
Created October 16, 2019 12:31
Node Clean Architecture - Frameworks-projectDependencies.js
const InMemoryDatabaseServices = require('../frameworks/persistance/InMemory/InMemoryDatabaseServices');
const UniversityCrmServices = require('../frameworks/externalServices/UniversityCrmServices');
module.exports = (() => {
return {
DatabaseService: new InMemoryDatabaseServices(),
CrmServices: new UniversityCrmServices()
};
})();
@royib
royib / projectDependenciesMongo.js
Created October 16, 2019 12:42
Node Clean Architecture - Frameworks-projectDependencies.js with mongoDb configuration
module.exports = (() => {
return {
DatabaseService: new MongoDBDatabaseServices(),
CrmServices: new UniversityCrmServices()
};
})();
@royib
royib / Entities.js
Last active October 17, 2019 19:48
Node Clean Architecture – Entities And Use Cases - Entities
module.exports = class Student {
constructor(id = null, firstName, lastName, email, Enrollments) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.Enrollments = Enrollments;
}
};
@royib
royib / queryContext.json
Last active October 28, 2019 08:28
Querying Elasticsearch- Query Context
{
"query": {
"bool": {
"must": [
{
"match": {
"street": "ditmas"
}
},
{
@royib
royib / filterContext.json
Created October 28, 2019 08:30
Querying Elasticsearch- filterContext
{
"query": {
"bool": {
"filter": {
"range": {
"age": {
"gte": 20,
"lte": 30
}
}