@drax/crud-back 2.11.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controllers/AbstractFastifyController.js +47 -24
- package/dist/repository/AbstractMongoRepository.js +12 -8
- package/dist/repository/AbstractSqliteRepository.js +40 -9
- package/dist/services/AbstractService.js +9 -6
- package/package.json +8 -7
- package/src/controllers/AbstractFastifyController.ts +56 -28
- package/src/repository/AbstractMongoRepository.ts +17 -8
- package/src/repository/AbstractSqliteRepository.ts +61 -10
- package/src/services/AbstractService.ts +12 -6
- package/test/_mocks/MockRepository.ts +1 -1
- package/test/controllers/PersonController.test.ts +547 -0
- package/test/people/controllers/CountryController.ts +40 -0
- package/test/people/controllers/LanguageController.ts +29 -0
- package/test/people/controllers/PersonController.ts +29 -0
- package/test/people/factory/services/CountryServiceFactory.ts +41 -0
- package/test/people/factory/services/LanguageServiceFactory.ts +41 -0
- package/test/people/factory/services/PersonServiceFactory.ts +41 -0
- package/test/people/interfaces/ICountry.ts +28 -0
- package/test/people/interfaces/ICountryRepository.ts +11 -0
- package/test/people/interfaces/ILanguage.ts +32 -0
- package/test/people/interfaces/ILanguageRepository.ts +11 -0
- package/test/people/interfaces/IPerson.ts +58 -0
- package/test/people/interfaces/IPersonRepository.ts +11 -0
- package/test/people/models/CountryModel.ts +38 -0
- package/test/people/models/LanguageModel.ts +40 -0
- package/test/people/models/PersonModel.ts +61 -0
- package/test/people/permissions/CountryPermissions.ts +14 -0
- package/test/people/permissions/LanguagePermissions.ts +14 -0
- package/test/people/permissions/PersonPermissions.ts +18 -0
- package/test/people/repository/mongo/CountryMongoRepository.ts +22 -0
- package/test/people/repository/mongo/LanguageMongoRepository.ts +22 -0
- package/test/people/repository/mongo/PersonMongoRepository.ts +22 -0
- package/test/people/repository/sqlite/CountrySqliteRepository.ts +33 -0
- package/test/people/repository/sqlite/LanguageSqliteRepository.ts +37 -0
- package/test/people/repository/sqlite/PersonSqliteRepository.ts +42 -0
- package/test/people/routes/CountryRoutes.ts +34 -0
- package/test/people/routes/LanguageRoutes.ts +34 -0
- package/test/people/routes/PersonRoutes.ts +40 -0
- package/test/people/schemas/CountrySchema.ts +22 -0
- package/test/people/schemas/LanguageSchema.ts +22 -0
- package/test/people/schemas/PersonSchema.ts +42 -0
- package/test/people/services/CountryService.ts +20 -0
- package/test/people/services/LanguageService.ts +20 -0
- package/test/people/services/PersonService.ts +20 -0
- package/test/services/AbstractService.test.ts +11 -7
- package/test/setup/MongoInMemory.ts +56 -0
- package/test/setup/TestSetup.ts +344 -0
- package/test/setup/data/admin-role.ts +13 -0
- package/test/setup/data/basic-user.ts +14 -0
- package/test/setup/data/one-tenant.ts +6 -0
- package/test/setup/data/restricted-role.ts +16 -0
- package/test/setup/data/root-user.ts +14 -0
- package/test/setup/data/tenant-one-user.ts +13 -0
- package/test/setup/data/tenant-two-user.ts +14 -0
- package/test/setup/data/two-tenant.ts +6 -0
- package/test/workers/ExportCsvWorker.test.ts +1 -1
- package/tsconfig.json +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/types/controllers/AbstractFastifyController.d.ts.map +1 -1
- package/types/repository/AbstractMongoRepository.d.ts +3 -3
- package/types/repository/AbstractMongoRepository.d.ts.map +1 -1
- package/types/repository/AbstractSqliteRepository.d.ts +5 -4
- package/types/repository/AbstractSqliteRepository.d.ts.map +1 -1
- package/types/services/AbstractService.d.ts +4 -2
- package/types/services/AbstractService.d.ts.map +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
import PersonServiceFactory from "../factory/services/PersonServiceFactory.js";
|
|
3
|
+
import {AbstractFastifyController} from "@drax/crud-back";
|
|
4
|
+
import PersonPermissions from "../permissions/PersonPermissions.js";
|
|
5
|
+
import type {IPerson, IPersonBase} from "../interfaces/IPerson";
|
|
6
|
+
|
|
7
|
+
class PersonController extends AbstractFastifyController<IPerson, IPersonBase, IPersonBase> {
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
super(PersonServiceFactory.instance, PersonPermissions)
|
|
11
|
+
this.tenantField = "tenant";
|
|
12
|
+
this.userField = "user";
|
|
13
|
+
|
|
14
|
+
this.tenantFilter = true;
|
|
15
|
+
this.tenantSetter = true;
|
|
16
|
+
this.tenantAssert = true;
|
|
17
|
+
|
|
18
|
+
this.userFilter = true;
|
|
19
|
+
this.userSetter = true;
|
|
20
|
+
this.userAssert = true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default PersonController;
|
|
26
|
+
export {
|
|
27
|
+
PersonController
|
|
28
|
+
}
|
|
29
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
import CountryMongoRepository from '../../repository/mongo/CountryMongoRepository.js'
|
|
3
|
+
import CountrySqliteRepository from '../../repository/sqlite/CountrySqliteRepository.js'
|
|
4
|
+
import type {ICountryRepository} from "../../interfaces/ICountryRepository";
|
|
5
|
+
import {CountryService} from '../../services/CountryService.js'
|
|
6
|
+
import {CountryBaseSchema, CountrySchema} from "../../schemas/CountrySchema.js";
|
|
7
|
+
import {COMMON, CommonConfig, DraxConfig} from "@drax/common-back";
|
|
8
|
+
|
|
9
|
+
class CountryServiceFactory {
|
|
10
|
+
private static service: CountryService;
|
|
11
|
+
|
|
12
|
+
public static get instance(): CountryService {
|
|
13
|
+
if (!CountryServiceFactory.service) {
|
|
14
|
+
|
|
15
|
+
let repository: ICountryRepository
|
|
16
|
+
switch (DraxConfig.getOrLoad(CommonConfig.DbEngine)) {
|
|
17
|
+
case COMMON.DB_ENGINES.MONGODB:
|
|
18
|
+
repository = new CountryMongoRepository()
|
|
19
|
+
break;
|
|
20
|
+
case COMMON.DB_ENGINES.SQLITE:
|
|
21
|
+
const dbFile = DraxConfig.getOrLoad(CommonConfig.SqliteDbFile)
|
|
22
|
+
repository = new CountrySqliteRepository(dbFile, false)
|
|
23
|
+
repository.build()
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error("DraxConfig.DB_ENGINE must be one of " + Object.values(COMMON.DB_ENGINES).join(", "));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const baseSchema = CountryBaseSchema;
|
|
30
|
+
const fullSchema = CountrySchema;
|
|
31
|
+
CountryServiceFactory.service = new CountryService(repository, baseSchema, fullSchema);
|
|
32
|
+
}
|
|
33
|
+
return CountryServiceFactory.service;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default CountryServiceFactory
|
|
38
|
+
export {
|
|
39
|
+
CountryServiceFactory
|
|
40
|
+
}
|
|
41
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
import LanguageMongoRepository from '../../repository/mongo/LanguageMongoRepository.js'
|
|
3
|
+
import LanguageSqliteRepository from '../../repository/sqlite/LanguageSqliteRepository.js'
|
|
4
|
+
import type {ILanguageRepository} from "../../interfaces/ILanguageRepository";
|
|
5
|
+
import {LanguageService} from '../../services/LanguageService.js'
|
|
6
|
+
import {LanguageBaseSchema, LanguageSchema} from "../../schemas/LanguageSchema.js";
|
|
7
|
+
import {COMMON, CommonConfig, DraxConfig} from "@drax/common-back";
|
|
8
|
+
|
|
9
|
+
class LanguageServiceFactory {
|
|
10
|
+
private static service: LanguageService;
|
|
11
|
+
|
|
12
|
+
public static get instance(): LanguageService {
|
|
13
|
+
if (!LanguageServiceFactory.service) {
|
|
14
|
+
|
|
15
|
+
let repository: ILanguageRepository
|
|
16
|
+
switch (DraxConfig.getOrLoad(CommonConfig.DbEngine)) {
|
|
17
|
+
case COMMON.DB_ENGINES.MONGODB:
|
|
18
|
+
repository = new LanguageMongoRepository()
|
|
19
|
+
break;
|
|
20
|
+
case COMMON.DB_ENGINES.SQLITE:
|
|
21
|
+
const dbFile = DraxConfig.getOrLoad(CommonConfig.SqliteDbFile)
|
|
22
|
+
repository = new LanguageSqliteRepository(dbFile, false)
|
|
23
|
+
repository.build()
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error("DraxConfig.DB_ENGINE must be one of " + Object.values(COMMON.DB_ENGINES).join(", "));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const baseSchema = LanguageBaseSchema;
|
|
30
|
+
const fullSchema = LanguageSchema;
|
|
31
|
+
LanguageServiceFactory.service = new LanguageService(repository, baseSchema, fullSchema);
|
|
32
|
+
}
|
|
33
|
+
return LanguageServiceFactory.service;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default LanguageServiceFactory
|
|
38
|
+
export {
|
|
39
|
+
LanguageServiceFactory
|
|
40
|
+
}
|
|
41
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
import PersonMongoRepository from '../../repository/mongo/PersonMongoRepository.js'
|
|
3
|
+
import PersonSqliteRepository from '../../repository/sqlite/PersonSqliteRepository.js'
|
|
4
|
+
import type {IPersonRepository} from "../../interfaces/IPersonRepository";
|
|
5
|
+
import {PersonService} from '../../services/PersonService.js'
|
|
6
|
+
import {PersonBaseSchema, PersonSchema} from "../../schemas/PersonSchema.js";
|
|
7
|
+
import {COMMON, CommonConfig, DraxConfig} from "@drax/common-back";
|
|
8
|
+
|
|
9
|
+
class PersonServiceFactory {
|
|
10
|
+
private static service: PersonService;
|
|
11
|
+
|
|
12
|
+
public static get instance(): PersonService {
|
|
13
|
+
if (!PersonServiceFactory.service) {
|
|
14
|
+
|
|
15
|
+
let repository: IPersonRepository
|
|
16
|
+
switch (DraxConfig.getOrLoad(CommonConfig.DbEngine)) {
|
|
17
|
+
case COMMON.DB_ENGINES.MONGODB:
|
|
18
|
+
repository = new PersonMongoRepository()
|
|
19
|
+
break;
|
|
20
|
+
case COMMON.DB_ENGINES.SQLITE:
|
|
21
|
+
const dbFile = DraxConfig.getOrLoad(CommonConfig.SqliteDbFile)
|
|
22
|
+
repository = new PersonSqliteRepository(dbFile, false)
|
|
23
|
+
repository.build()
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error("DraxConfig.DB_ENGINE must be one of " + Object.values(COMMON.DB_ENGINES).join(", "));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const baseSchema = PersonBaseSchema;
|
|
30
|
+
const fullSchema = PersonSchema;
|
|
31
|
+
PersonServiceFactory.service = new PersonService(repository, baseSchema, fullSchema);
|
|
32
|
+
}
|
|
33
|
+
return PersonServiceFactory.service;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default PersonServiceFactory
|
|
38
|
+
export {
|
|
39
|
+
PersonServiceFactory
|
|
40
|
+
}
|
|
41
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
interface ICountryBase {
|
|
3
|
+
name: string
|
|
4
|
+
description?: string
|
|
5
|
+
flag?: string
|
|
6
|
+
metadata?: Record<string, any>
|
|
7
|
+
tenant?: any
|
|
8
|
+
createdBy: any
|
|
9
|
+
createdAt?: Date
|
|
10
|
+
updatedAt?: Date
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ICountry {
|
|
14
|
+
_id: string
|
|
15
|
+
name: string
|
|
16
|
+
description?: string
|
|
17
|
+
flag?: string
|
|
18
|
+
metadata?: Record<string, any>
|
|
19
|
+
tenant?: any
|
|
20
|
+
createdBy: any
|
|
21
|
+
createdAt?: Date
|
|
22
|
+
updatedAt?: Date
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type {
|
|
26
|
+
ICountryBase,
|
|
27
|
+
ICountry
|
|
28
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
interface ILanguageBase {
|
|
3
|
+
name: string
|
|
4
|
+
icon?: {
|
|
5
|
+
filename: string,
|
|
6
|
+
filepath: string,
|
|
7
|
+
size: number,
|
|
8
|
+
mimetype?: string,
|
|
9
|
+
url: string
|
|
10
|
+
}
|
|
11
|
+
createdAt?: Date
|
|
12
|
+
updatedAt?: Date
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ILanguage {
|
|
16
|
+
_id: string
|
|
17
|
+
name: string
|
|
18
|
+
icon?: {
|
|
19
|
+
filename: string,
|
|
20
|
+
filepath: string,
|
|
21
|
+
size: number,
|
|
22
|
+
mimetype?: string,
|
|
23
|
+
url: string
|
|
24
|
+
}
|
|
25
|
+
createdAt?: Date
|
|
26
|
+
updatedAt?: Date
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type {
|
|
30
|
+
ILanguageBase,
|
|
31
|
+
ILanguage
|
|
32
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
import type {ILanguage, ILanguageBase} from './ILanguage'
|
|
3
|
+
import {IDraxCrudRepository} from "@drax/crud-share";
|
|
4
|
+
|
|
5
|
+
interface ILanguageRepository extends IDraxCrudRepository<ILanguage, ILanguageBase, ILanguageBase>{
|
|
6
|
+
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {ILanguageRepository}
|
|
10
|
+
|
|
11
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
interface IPersonBase {
|
|
3
|
+
fullname: string
|
|
4
|
+
live?: boolean
|
|
5
|
+
birthdate?: Date
|
|
6
|
+
secret?: string
|
|
7
|
+
money?: number
|
|
8
|
+
nationality?: any
|
|
9
|
+
hobbies?: Array<string>
|
|
10
|
+
race?: string
|
|
11
|
+
interests?: Array<string>
|
|
12
|
+
languages?: Array<any>
|
|
13
|
+
address?: { country?: string
|
|
14
|
+
city?: string
|
|
15
|
+
street: string
|
|
16
|
+
zip?: number
|
|
17
|
+
casa?: boolean}
|
|
18
|
+
skills?: Array<{
|
|
19
|
+
name: string
|
|
20
|
+
level?: number
|
|
21
|
+
}>
|
|
22
|
+
tenant?: any
|
|
23
|
+
user?: any
|
|
24
|
+
createdAt?: Date
|
|
25
|
+
updatedAt?: Date
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface IPerson {
|
|
29
|
+
_id: string
|
|
30
|
+
fullname: string
|
|
31
|
+
live?: boolean
|
|
32
|
+
birthdate?: Date
|
|
33
|
+
secret?: string
|
|
34
|
+
money?: number
|
|
35
|
+
nationality?: any
|
|
36
|
+
hobbies?: Array<string>
|
|
37
|
+
race?: string
|
|
38
|
+
interests?: Array<string>
|
|
39
|
+
languages?: Array<any>
|
|
40
|
+
address?: { country?: string
|
|
41
|
+
city?: string
|
|
42
|
+
street: string
|
|
43
|
+
zip?: number
|
|
44
|
+
casa?: boolean}
|
|
45
|
+
skills?: Array<{
|
|
46
|
+
name: string
|
|
47
|
+
level?: number
|
|
48
|
+
}>
|
|
49
|
+
tenant?: any
|
|
50
|
+
user?: any
|
|
51
|
+
createdAt?: Date
|
|
52
|
+
updatedAt?: Date
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type {
|
|
56
|
+
IPersonBase,
|
|
57
|
+
IPerson
|
|
58
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import {mongoose} from '@drax/common-back';
|
|
3
|
+
import {PaginateModel} from "mongoose";
|
|
4
|
+
import uniqueValidator from 'mongoose-unique-validator';
|
|
5
|
+
import mongoosePaginate from 'mongoose-paginate-v2'
|
|
6
|
+
import type {ICountry} from '../interfaces/ICountry'
|
|
7
|
+
|
|
8
|
+
const CountrySchema = new mongoose.Schema<ICountry>({
|
|
9
|
+
name: {type: String, required: true, index: true, unique: true },
|
|
10
|
+
description: {type: String, required: false, index: false, unique: false },
|
|
11
|
+
flag: {type: String, required: false, index: false, unique: false },
|
|
12
|
+
metadata: {type: mongoose.Schema.Types.Mixed, required: false, index: false, unique: false },
|
|
13
|
+
tenant: {type: mongoose.Schema.Types.ObjectId, ref: 'Tenant', required: false, index: false, unique: false },
|
|
14
|
+
createdBy: {type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true, index: false, unique: false }
|
|
15
|
+
}, {timestamps: true});
|
|
16
|
+
|
|
17
|
+
CountrySchema.plugin(uniqueValidator, {message: 'validation.unique'});
|
|
18
|
+
CountrySchema.plugin(mongoosePaginate);
|
|
19
|
+
|
|
20
|
+
CountrySchema.virtual("id").get(function () {
|
|
21
|
+
return this._id.toString();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
CountrySchema.set('toJSON', {getters: true, virtuals: true});
|
|
26
|
+
|
|
27
|
+
CountrySchema.set('toObject', {getters: true, virtuals: true});
|
|
28
|
+
|
|
29
|
+
const MODEL_NAME = 'Country';
|
|
30
|
+
const COLLECTION_NAME = 'Country';
|
|
31
|
+
const CountryModel = mongoose.model<ICountry, PaginateModel<ICountry>>(MODEL_NAME, CountrySchema,COLLECTION_NAME);
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
CountrySchema,
|
|
35
|
+
CountryModel
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default CountryModel
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
import {mongoose} from '@drax/common-back';
|
|
3
|
+
import {PaginateModel} from "mongoose";
|
|
4
|
+
import uniqueValidator from 'mongoose-unique-validator';
|
|
5
|
+
import mongoosePaginate from 'mongoose-paginate-v2'
|
|
6
|
+
import type {ILanguage} from '../interfaces/ILanguage'
|
|
7
|
+
|
|
8
|
+
const LanguageSchema = new mongoose.Schema<ILanguage>({
|
|
9
|
+
name: {type: String, required: true, index: true, unique: true },
|
|
10
|
+
icon: {
|
|
11
|
+
filename: {type: String , required: false, index: false, unique: false },
|
|
12
|
+
filepath: {type: String , required: false, index: false, unique: false },
|
|
13
|
+
size: {type: Number , required: false, index: false, unique: false },
|
|
14
|
+
mimetype: {type: String , required: false, index: false, unique: false },
|
|
15
|
+
url: {type: String , required: false, index: false, unique: false },
|
|
16
|
+
}
|
|
17
|
+
}, {timestamps: true});
|
|
18
|
+
|
|
19
|
+
LanguageSchema.plugin(uniqueValidator, {message: 'validation.unique'});
|
|
20
|
+
LanguageSchema.plugin(mongoosePaginate);
|
|
21
|
+
|
|
22
|
+
LanguageSchema.virtual("id").get(function () {
|
|
23
|
+
return this._id.toString();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
LanguageSchema.set('toJSON', {getters: true, virtuals: true});
|
|
28
|
+
|
|
29
|
+
LanguageSchema.set('toObject', {getters: true, virtuals: true});
|
|
30
|
+
|
|
31
|
+
const MODEL_NAME = 'Language';
|
|
32
|
+
const COLLECTION_NAME = 'Language';
|
|
33
|
+
const LanguageModel = mongoose.model<ILanguage, PaginateModel<ILanguage>>(MODEL_NAME, LanguageSchema,COLLECTION_NAME);
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
LanguageSchema,
|
|
37
|
+
LanguageModel
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default LanguageModel
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {mongoose} from '@drax/common-back';
|
|
2
|
+
import {PaginateModel} from "mongoose";
|
|
3
|
+
import uniqueValidator from 'mongoose-unique-validator';
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import mongoosePaginate from 'mongoose-paginate-v2'
|
|
6
|
+
import type {IPerson} from '../interfaces/IPerson'
|
|
7
|
+
|
|
8
|
+
const PersonSchema = new mongoose.Schema<IPerson>({
|
|
9
|
+
fullname: {type: String, required: true, index: true, unique: true},
|
|
10
|
+
live: {type: Boolean, required: false, index: false, unique: false},
|
|
11
|
+
birthdate: {type: Date, required: false, index: false, unique: false},
|
|
12
|
+
secret: {type: String, required: false, index: false, unique: false},
|
|
13
|
+
money: {type: Number, required: false, index: false, unique: false},
|
|
14
|
+
nationality: {type: mongoose.Schema.Types.ObjectId, ref: 'Country', required: false, index: false, unique: false},
|
|
15
|
+
hobbies: [{type: String, required: false, index: false, unique: false}],
|
|
16
|
+
race: {type: String, enum: ['human', 'elf', 'orc'], required: false, index: false, unique: false},
|
|
17
|
+
interests: [{
|
|
18
|
+
type: String,
|
|
19
|
+
enum: ['sports', 'music', 'reading', 'travel', 'cooking', 'technology'],
|
|
20
|
+
required: false,
|
|
21
|
+
index: false,
|
|
22
|
+
unique: false
|
|
23
|
+
}],
|
|
24
|
+
languages: [{type: mongoose.Schema.Types.ObjectId, ref: 'Language', required: false, index: false, unique: false}],
|
|
25
|
+
address: {
|
|
26
|
+
country: {type: String, required: false, index: false, unique: false},
|
|
27
|
+
city: {type: String, required: false, index: false, unique: false},
|
|
28
|
+
street: {type: String, required: true, index: false, unique: false},
|
|
29
|
+
zip: {type: Number, required: false, index: false, unique: false},
|
|
30
|
+
casa: {type: Boolean, required: false, index: false, unique: false}
|
|
31
|
+
},
|
|
32
|
+
skills: [{
|
|
33
|
+
name: {type: String, required: true, index: false, unique: false},
|
|
34
|
+
level: {type: Number, required: false, index: false, unique: false}
|
|
35
|
+
}],
|
|
36
|
+
tenant: {type: mongoose.Schema.Types.ObjectId, ref: 'Tenant', required: false, index: false, unique: false},
|
|
37
|
+
user: {type: mongoose.Schema.Types.ObjectId, ref: 'User', required: false, index: false, unique: false}
|
|
38
|
+
}, {timestamps: true});
|
|
39
|
+
|
|
40
|
+
PersonSchema.plugin(uniqueValidator, {message: 'validation.unique'});
|
|
41
|
+
PersonSchema.plugin(mongoosePaginate);
|
|
42
|
+
|
|
43
|
+
PersonSchema.virtual("id").get(function () {
|
|
44
|
+
return this._id.toString();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
PersonSchema.set('toJSON', {getters: true, virtuals: true});
|
|
49
|
+
|
|
50
|
+
PersonSchema.set('toObject', {getters: true, virtuals: true});
|
|
51
|
+
|
|
52
|
+
const MODEL_NAME = 'Person';
|
|
53
|
+
const COLLECTION_NAME = 'Person';
|
|
54
|
+
const PersonModel = mongoose.model<IPerson, PaginateModel<IPerson>>(MODEL_NAME, PersonSchema, COLLECTION_NAME);
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
PersonSchema,
|
|
58
|
+
PersonModel
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default PersonModel
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
enum CountryPermissions {
|
|
3
|
+
|
|
4
|
+
Create = "country:create",
|
|
5
|
+
Update = "country:update",
|
|
6
|
+
Delete = "country:delete",
|
|
7
|
+
View = "country:view",
|
|
8
|
+
Manage = "country:manage"
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { CountryPermissions };
|
|
13
|
+
export default CountryPermissions;
|
|
14
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
enum LanguagePermissions {
|
|
3
|
+
|
|
4
|
+
Create = "language:create",
|
|
5
|
+
Update = "language:update",
|
|
6
|
+
Delete = "language:delete",
|
|
7
|
+
View = "language:view",
|
|
8
|
+
Manage = "language:manage"
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { LanguagePermissions };
|
|
13
|
+
export default LanguagePermissions;
|
|
14
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
enum PersonPermissions {
|
|
3
|
+
|
|
4
|
+
Create = "person:create",
|
|
5
|
+
Update = "person:update",
|
|
6
|
+
Delete = "person:delete",
|
|
7
|
+
View = "person:view",
|
|
8
|
+
Manage = "person:manage",
|
|
9
|
+
|
|
10
|
+
ViewAll = "person:viewAll",
|
|
11
|
+
UpdateAll = "person:updateAll",
|
|
12
|
+
DeleteAll = "person:deleteAll",
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { PersonPermissions };
|
|
17
|
+
export default PersonPermissions;
|
|
18
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import {AbstractMongoRepository} from "@drax/crud-back";
|
|
3
|
+
import {CountryModel} from "../../models/CountryModel.js";
|
|
4
|
+
import type {ICountryRepository} from '../../interfaces/ICountryRepository'
|
|
5
|
+
import type {ICountry, ICountryBase} from "../../interfaces/ICountry";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class CountryMongoRepository extends AbstractMongoRepository<ICountry, ICountryBase, ICountryBase> implements ICountryRepository {
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this._model = CountryModel;
|
|
13
|
+
this._searchFields = ['name'];
|
|
14
|
+
this._populateFields = ['tenant', 'createdBy'];
|
|
15
|
+
this._lean = true
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default CountryMongoRepository
|
|
21
|
+
export {CountryMongoRepository}
|
|
22
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import {AbstractMongoRepository} from "@drax/crud-back";
|
|
3
|
+
import {LanguageModel} from "../../models/LanguageModel.js";
|
|
4
|
+
import type {ILanguageRepository} from '../../interfaces/ILanguageRepository'
|
|
5
|
+
import type {ILanguage, ILanguageBase} from "../../interfaces/ILanguage";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LanguageMongoRepository extends AbstractMongoRepository<ILanguage, ILanguageBase, ILanguageBase> implements ILanguageRepository {
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this._model = LanguageModel;
|
|
13
|
+
this._searchFields = ['name'];
|
|
14
|
+
this._populateFields = [];
|
|
15
|
+
this._lean = true
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default LanguageMongoRepository
|
|
21
|
+
export {LanguageMongoRepository}
|
|
22
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import {AbstractMongoRepository} from "@drax/crud-back";
|
|
3
|
+
import {PersonModel} from "../../models/PersonModel.js";
|
|
4
|
+
import type {IPersonRepository} from '../../interfaces/IPersonRepository'
|
|
5
|
+
import type {IPerson, IPersonBase} from "../../interfaces/IPerson";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PersonMongoRepository extends AbstractMongoRepository<IPerson, IPersonBase, IPersonBase> implements IPersonRepository {
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this._model = PersonModel;
|
|
13
|
+
this._searchFields = ['fullname', 'hobbies', 'race', 'interests'];
|
|
14
|
+
this._populateFields = ['nationality', 'languages', 'tenant', 'user'];
|
|
15
|
+
this._lean = true
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default PersonMongoRepository
|
|
21
|
+
export {PersonMongoRepository}
|
|
22
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
import {AbstractSqliteRepository} from "@drax/crud-back";
|
|
3
|
+
import type {ICountryRepository} from '../../interfaces/ICountryRepository'
|
|
4
|
+
import type {ICountry, ICountryBase} from "../../interfaces/ICountry";
|
|
5
|
+
import {SqliteTableField} from "@drax/common-back";
|
|
6
|
+
|
|
7
|
+
class CountrySqliteRepository extends AbstractSqliteRepository<ICountry, ICountryBase, ICountryBase> implements ICountryRepository {
|
|
8
|
+
|
|
9
|
+
protected db: any;
|
|
10
|
+
protected tableName: string = 'Country';
|
|
11
|
+
protected dataBaseFile: string;
|
|
12
|
+
protected searchFields: string[] = ['name'];
|
|
13
|
+
protected booleanFields: string[] = [];
|
|
14
|
+
protected identifier: string = '_id';
|
|
15
|
+
protected populateFields = [
|
|
16
|
+
{ field: 'tenant', table: 'tenant', identifier: '_id' },
|
|
17
|
+
{ field: 'createdBy', table: 'createdBy', identifier: '_id' }
|
|
18
|
+
]
|
|
19
|
+
protected verbose: boolean = false;
|
|
20
|
+
protected tableFields: SqliteTableField[] = [
|
|
21
|
+
{name: "name", type: "TEXT", unique: true, primary: false},
|
|
22
|
+
{name: "description", type: "TEXT", unique: false, primary: false},
|
|
23
|
+
{name: "flag", type: "TEXT", unique: false, primary: false},
|
|
24
|
+
{name: "metadata", type: "TEXT", unique: false, primary: false},
|
|
25
|
+
{name: "tenant", type: "TEXT", unique: false, primary: false},
|
|
26
|
+
{name: "createdBy", type: "TEXT", unique: false, primary: false}
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default CountrySqliteRepository
|
|
32
|
+
export {CountrySqliteRepository}
|
|
33
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
import {AbstractSqliteRepository} from "@drax/crud-back";
|
|
3
|
+
import type {ILanguageRepository} from '../../interfaces/ILanguageRepository'
|
|
4
|
+
import type {ILanguage, ILanguageBase} from "../../interfaces/ILanguage";
|
|
5
|
+
import {SqliteTableField} from "@drax/common-back";
|
|
6
|
+
|
|
7
|
+
class LanguageSqliteRepository extends AbstractSqliteRepository<ILanguage, ILanguageBase, ILanguageBase> implements ILanguageRepository {
|
|
8
|
+
|
|
9
|
+
protected db: any;
|
|
10
|
+
protected tableName: string = 'Language';
|
|
11
|
+
protected dataBaseFile: string;
|
|
12
|
+
protected searchFields: string[] = ['name'];
|
|
13
|
+
protected booleanFields: string[] = [];
|
|
14
|
+
protected identifier: string = '_id';
|
|
15
|
+
protected populateFields = [
|
|
16
|
+
|
|
17
|
+
]
|
|
18
|
+
protected verbose: boolean = false;
|
|
19
|
+
protected tableFields: SqliteTableField[] = [
|
|
20
|
+
{name: "name", type: "TEXT", unique: true, primary: false},
|
|
21
|
+
{name: "icon", type: "TEXT", unique: false, primary: false}
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
async prepareData(data: any): Promise<any> {
|
|
26
|
+
data.icon = JSON.stringify(data.icon)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async prepareItem(item: any): Promise<any> {
|
|
30
|
+
item.icon = JSON.parse(item.icon)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default LanguageSqliteRepository
|
|
36
|
+
export {LanguageSqliteRepository}
|
|
37
|
+
|