secjs / base Goto Github PK
View Code? Open in Web Editor NEW๐ Base classes with prebuild methods for Node.js
License: MIT License
๐ Base classes with prebuild methods for Node.js
License: MIT License
Better errors inside prisma
meta.itemCount
from paginate function is always wrong in MongooseRepository, because the query is making the pagination, and mongoose see its as part of the query, so the countDocuments
only returns the pagination.limit
number.
isInternRequest needs to be always a true value inside repositories base
Add PrismaRepository to repositories base:
import { User } from 'app/Models/User'
import { PrismaRepository } from '@secjs/base/repositories/PrismaRepository'
class UserRepository extends PrismaRepository<User> {
protected wheres: ['id', 'name'] // What wheres can be executed by client.
protected relations: ['contacts'] // What relations can be get by client.
// Both, wheres and relations will only work for external requests.
protected Model = User // Give the Model value to Lucid, so he knows what to work with.
// You can subscribe PrismaRepository methods in here if you want!
}
Object.keys(where).forEach(key => {
let value = where[key];
if (value === 'null') value = null
if (value === '!null') value = { $ne: null }
if (Array.isArray(value)) {
value = { $in: value }
}
if (value.includes('->')) {
const firstValue = value.split('->')[0].replace(/\s/g, '')
const secondValue = value.split('->')[1].replace(/\s/g, '')
value = { $gte: firstValue, $lte: secondValue }
}
query.where(key, value);
});
In MongoDB sometimes you want to create a simple relationship between two schemas. It's very easy when you want to create OneToMany and populate the side of ManyToOne. The problem is when you want to populate the other side.
class UserSchema {
products: ProductSchema[]
}
class ProductSchema {
user: UserSchema
}
UserSchema.populate('products') // Will bring an empty array
ProductSchema.populate('user') // Will bring the user object owner from that product
To solve this empty array updateOneToMany function needs to be implemented and will receive three parameters:
class UserSchema {
products: ProductSchema[]
}
class ProductSchema {
user: UserSchema
}
const user = new UserSchema()
const product = new ProductSchema({ user })
await this.userRepository.updateOneToMany(user.id, product.id, 'products')
UserSchema.populate('products') // Will bring an array with all user products
ProductSchema.populate('user') // Will bring the user object owner from that product
The errors that are being throwed are from the main Error class from JavaScript. At @secjs/exceptions we have a lot more information about the error.
MongooseRepository is not validating the data inside wheres
and relations
arrays.
value.includes is throwing an error when value is not a string
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.