Repository pattern or how I made business logic simpler
About the the article
Let me share you an interesting story how usage of repository pattern helps me to made business logic simpler and hide data storage integration details
What is repository pattern?
Repository - component which provide you an interface to manipulate some data on some specific data storage, but hides all storage-specific implementation details.
Sound too abstract, isn’t it? In simple words it is some class, functions, module or whatever what gives you an interface to create, read, update, delete some data on some data storage.
Let’s simulate some situation on some project
For a context it is an application to manage user files. It has pretty simple features:
- upload file
- download file
In first implementation files were stored directly on server (it was a start up with 5 clients and it was enough)
// we use async version of fs module
const fs = require('fs/promises');class FileRepository { async getFile(userId, fileName) {
const filePath = `/storage/${userId}/${fileName}`;
const…