tt-entities 0.0.1

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.
Files changed (29) hide show
  1. package/.prettierrc +4 -0
  2. package/.sequelizerc +6 -0
  3. package/README.md +98 -0
  4. package/dist/main.js +714 -0
  5. package/eslint.config.mjs +35 -0
  6. package/libs/tatayab-entities-library/src/entities/apikey.entity.ts +33 -0
  7. package/libs/tatayab-entities-library/src/entities/area.entity.ts +24 -0
  8. package/libs/tatayab-entities-library/src/entities/country.entity.ts +15 -0
  9. package/libs/tatayab-entities-library/src/entities/sys.role.entity.ts +7 -0
  10. package/libs/tatayab-entities-library/src/entities/sys.user.entity.ts +49 -0
  11. package/libs/tatayab-entities-library/src/entities/translation.entity.ts +17 -0
  12. package/libs/tatayab-entities-library/src/entities/user.entity.ts +85 -0
  13. package/libs/tatayab-entities-library/src/index.ts +12 -0
  14. package/libs/tatayab-entities-library/src/utils/enums/gender.ts +5 -0
  15. package/libs/tatayab-entities-library/src/utils/enums/language.ts +4 -0
  16. package/libs/tatayab-entities-library/src/utils/enums/osName.ts +5 -0
  17. package/libs/tatayab-entities-library/src/utils/enums/productApp.ts +4 -0
  18. package/libs/tatayab-entities-library/src/utils/enums/status.ts +4 -0
  19. package/libs/tatayab-entities-library/src/utils/enums/versiontype.ts +4 -0
  20. package/libs/tatayab-entities-library/tsconfig.lib.json +9 -0
  21. package/nest-cli.json +18 -0
  22. package/package.json +84 -0
  23. package/src/app.module.ts +26 -0
  24. package/src/database/config.js +35 -0
  25. package/src/main.ts +8 -0
  26. package/test/app.e2e-spec.ts +25 -0
  27. package/test/jest-e2e.json +9 -0
  28. package/tsconfig.build.json +4 -0
  29. package/tsconfig.json +25 -0
@@ -0,0 +1,35 @@
1
+ // @ts-check
2
+ import eslint from '@eslint/js';
3
+ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
4
+ import globals from 'globals';
5
+ import tseslint from 'typescript-eslint';
6
+
7
+ export default tseslint.config(
8
+ {
9
+ ignores: ['eslint.config.mjs'],
10
+ },
11
+ eslint.configs.recommended,
12
+ ...tseslint.configs.recommendedTypeChecked,
13
+ eslintPluginPrettierRecommended,
14
+ {
15
+ languageOptions: {
16
+ globals: {
17
+ ...globals.node,
18
+ ...globals.jest,
19
+ },
20
+ sourceType: 'commonjs',
21
+ parserOptions: {
22
+ projectService: true,
23
+ tsconfigRootDir: import.meta.dirname,
24
+ },
25
+ },
26
+ },
27
+ {
28
+ rules: {
29
+ '@typescript-eslint/no-explicit-any': 'off',
30
+ '@typescript-eslint/no-floating-promises': 'warn',
31
+ '@typescript-eslint/no-unsafe-argument': 'warn',
32
+ "prettier/prettier": ["error", { endOfLine: "auto" }],
33
+ },
34
+ },
35
+ );
@@ -0,0 +1,33 @@
1
+ import { Column, DataType, Model, Table } from 'sequelize-typescript';
2
+ import { Status } from '../utils/enums/status';
3
+ import { VersionType } from '../utils/enums/versiontype';
4
+ import { OsName } from '../utils/enums/osName';
5
+ import { ProductApp } from '../utils/enums/productApp';
6
+
7
+ @Table
8
+ class ApiKey extends Model {
9
+ @Column
10
+ hashedApiKey: string;
11
+ @Column({ type: DataType.ENUM(...Object.values(OsName)) })
12
+ system: OsName;
13
+ @Column({ type: DataType.ENUM(...Object.values(ProductApp)) })
14
+ appName: ProductApp;
15
+ @Column
16
+ appVersion: string;
17
+ @Column
18
+ expiryDate: Date;
19
+ @Column({
20
+ type: DataType.ENUM(...Object.values(Status)),
21
+ defaultValue: Status.ACTIVE,
22
+ })
23
+ status: Status;
24
+ @Column
25
+ isReleased: boolean;
26
+ @Column({
27
+ type: DataType.ENUM(...Object.values(VersionType)),
28
+ defaultValue: VersionType.OPTIONAL,
29
+ })
30
+ versionType: VersionType;
31
+ }
32
+
33
+ export default ApiKey;
@@ -0,0 +1,24 @@
1
+ import {
2
+ BelongsTo,
3
+ Column,
4
+ ForeignKey,
5
+ Model,
6
+ Table,
7
+ } from 'sequelize-typescript';
8
+ import { Country } from './country.entity';
9
+
10
+ @Table
11
+ export class Area extends Model {
12
+ @ForeignKey(() => Country)
13
+ @Column({
14
+ allowNull: false,
15
+ validate: { notNull: { msg: 'County Id Required' } },
16
+ })
17
+ countryId!: number;
18
+
19
+ @Column
20
+ parentId?: number;
21
+
22
+ @BelongsTo(() => Country)
23
+ country: Country;
24
+ }
@@ -0,0 +1,15 @@
1
+ import { Column, Model, Table } from 'sequelize-typescript';
2
+
3
+ @Table
4
+ export class Country extends Model {
5
+ @Column
6
+ flagIcon: string;
7
+ @Column
8
+ isoCode: string;
9
+ @Column
10
+ phoneExt: string;
11
+ @Column
12
+ currency: string;
13
+ @Column
14
+ exchangeRateToKwd: number;
15
+ }
@@ -0,0 +1,7 @@
1
+ import { Column, Model, Table } from 'sequelize-typescript';
2
+
3
+ @Table
4
+ export class SysRole extends Model {
5
+ @Column
6
+ name: string;
7
+ }
@@ -0,0 +1,49 @@
1
+ import {
2
+ BelongsTo,
3
+ Column,
4
+ DataType,
5
+ ForeignKey,
6
+ Model,
7
+ Table,
8
+ } from 'sequelize-typescript';
9
+ import { Status } from '../utils/enums/status';
10
+ import { SysRole } from './sys.role.entity';
11
+
12
+ @Table
13
+ export class SysUser extends Model {
14
+ @Column
15
+ name!: string;
16
+
17
+ @Column({ allowNull: false, validate: { unique: true } })
18
+ username!: string;
19
+
20
+ @Column
21
+ email!: string;
22
+
23
+ @Column
24
+ phoneExt!: string;
25
+
26
+ @Column
27
+ phone!: string;
28
+
29
+ @Column
30
+ password!: string;
31
+ @Column({
32
+ type: DataType.ENUM(...Object.values(Status)),
33
+ defaultValue: Status.ACTIVE,
34
+ })
35
+ status?: Status;
36
+
37
+ @ForeignKey(() => SysRole)
38
+ @Column
39
+ roleId: number;
40
+
41
+ @Column
42
+ profilePicture: string;
43
+
44
+ @Column
45
+ lastLogin: Date;
46
+
47
+ @BelongsTo(() => SysRole)
48
+ role: SysRole;
49
+ }
@@ -0,0 +1,17 @@
1
+ import { Column, Model, Table } from 'sequelize-typescript';
2
+
3
+ @Table
4
+ export class Translation extends Model {
5
+ @Column
6
+ text: string;
7
+ @Column
8
+ shortDesc?: string;
9
+ @Column
10
+ longDesc?: string;
11
+ @Column
12
+ locale: string;
13
+ @Column
14
+ entityId: string;
15
+ @Column
16
+ entityName: string;
17
+ }
@@ -0,0 +1,85 @@
1
+ import {
2
+ Model,
3
+ Table,
4
+ Column,
5
+ ForeignKey,
6
+ BelongsTo,
7
+ DataType,
8
+ } from 'sequelize-typescript';
9
+ import { Status } from '../utils/enums/status';
10
+ import { Language } from '../utils/enums/language';
11
+ import { Country } from './country.entity';
12
+ import { Gender } from '../utils/enums/gender';
13
+
14
+ @Table
15
+ export class User extends Model {
16
+ @Column
17
+ firstName?: string;
18
+
19
+ @Column
20
+ lastName?: string;
21
+
22
+ @Column
23
+ password!: string;
24
+
25
+ @Column({
26
+ type: DataType.ENUM(...Object.values(Status)),
27
+ defaultValue: Status.ACTIVE,
28
+ })
29
+ status: Status;
30
+
31
+ @Column({ allowNull: false, validate: { isEmail: { msg: 'Invalid Email' } } })
32
+ email!: string;
33
+
34
+ @Column
35
+ phone?: string;
36
+
37
+ @Column
38
+ phoneExt?: string;
39
+
40
+ @Column
41
+ birthday?: Date;
42
+
43
+ @Column
44
+ facebookId?: string;
45
+
46
+ @Column
47
+ googleId?: string;
48
+
49
+ @Column
50
+ appleId?: string;
51
+
52
+ @Column({
53
+ type: DataType.ENUM(...Object.values(Language)),
54
+ defaultValue: Language.ENGLISH,
55
+ })
56
+ preferredLanguage: Language;
57
+
58
+ @ForeignKey(() => Country)
59
+ @Column
60
+ preferredCountryId?: number;
61
+
62
+ @Column
63
+ profilePic?: string;
64
+
65
+ @Column
66
+ lastLogin!: Date;
67
+
68
+ @Column({ allowNull: false, defaultValue: false })
69
+ isBlocked!: boolean;
70
+
71
+ @Column({ defaultValue: false })
72
+ isVerified: boolean;
73
+
74
+ @Column
75
+ refCode: string;
76
+
77
+ @Column({
78
+ type: DataType.ENUM(...Object.values(Gender)),
79
+ defaultValue: Gender.PREFER_NOT_TO_SAY,
80
+ })
81
+ gender: Gender;
82
+
83
+ @BelongsTo(() => Country)
84
+ country: Country;
85
+ }
@@ -0,0 +1,12 @@
1
+ import { ModelCtor } from 'sequelize-typescript';
2
+ import { Country } from './entities/country.entity';
3
+ import { Translation } from './entities/translation.entity';
4
+ import ApiKey from './entities/apikey.entity';
5
+ import { Area } from './entities/area.entity';
6
+ import { SysRole } from './entities/sys.role.entity';
7
+ import { SysUser } from './entities/sys.user.entity';
8
+ import { User } from './entities/user.entity';
9
+
10
+ export function getDbModels(): ModelCtor[] {
11
+ return [ApiKey, Area, Country, SysRole, SysUser, Translation, User];
12
+ }
@@ -0,0 +1,5 @@
1
+ export enum Gender {
2
+ MALE = 'Male',
3
+ FEMALE = 'Female',
4
+ PREFER_NOT_TO_SAY = 'Prefer not to say',
5
+ }
@@ -0,0 +1,4 @@
1
+ export enum Language {
2
+ ENGLISH = 'en',
3
+ ARABIC = 'ar',
4
+ }
@@ -0,0 +1,5 @@
1
+ export enum OsName {
2
+ ANDROID = 'android',
3
+ IOS = 'iOS',
4
+ WEB = 'web',
5
+ }
@@ -0,0 +1,4 @@
1
+ export enum ProductApp {
2
+ DASHBOARD = 'dashboard',
3
+ USER_APP = 'userapp',
4
+ }
@@ -0,0 +1,4 @@
1
+ export enum Status {
2
+ ACTIVE = 'active',
3
+ IN_ACTIVE = 'inactive',
4
+ }
@@ -0,0 +1,4 @@
1
+ export enum VersionType {
2
+ OPTIONAL = 'optional',
3
+ MANDATORY = 'mandatory',
4
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "outDir": "../../dist/libs/trycar-entities-library"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
9
+ }
package/nest-cli.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "collection": "@nestjs/schematics",
3
+ "sourceRoot": "src",
4
+ "projects": {
5
+ "trycar-entities-library": {
6
+ "type": "library",
7
+ "root": "libs/trycar-entities-library",
8
+ "entryFile": "index",
9
+ "sourceRoot": "libs/trycar-entities-library/src",
10
+ "compilerOptions": {
11
+ "tsConfigPath": "libs/trycar-entities-library/tsconfig.lib.json"
12
+ }
13
+ }
14
+ },
15
+ "compilerOptions": {
16
+ "webpack": true
17
+ }
18
+ }
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "tt-entities",
3
+ "version": "0.0.1",
4
+ "description": "Tatayab entities library",
5
+ "main": "dist/libs/index.js",
6
+ "types": "dist/libs/index.d.ts",
7
+ "keywords": [],
8
+ "author": "Tatayab <technical@tatayab.com>",
9
+ "license": "ISC",
10
+ "bugs": {
11
+ "url": ""
12
+ },
13
+ "scripts": {
14
+ "build": "nest build",
15
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
16
+ "start": "nest start",
17
+ "start:dev": "nest start --watch",
18
+ "start:debug": "nest start --debug --watch",
19
+ "start:prod": "node dist/main",
20
+ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
21
+ "test": "jest",
22
+ "test:watch": "jest --watch",
23
+ "test:cov": "jest --coverage",
24
+ "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
25
+ "test:e2e": "jest --config ./test/jest-e2e.json",
26
+ "publish-tt": "npm run build && npm publish"
27
+ },
28
+ "dependencies": {
29
+ "@nestjs/common": "^11.0.1",
30
+ "@nestjs/config": "^4.0.3",
31
+ "@nestjs/core": "^11.0.1",
32
+ "@nestjs/platform-express": "^11.0.1",
33
+ "@nestjs/sequelize": "^11.0.1",
34
+ "class-validator": "^0.15.1",
35
+ "mysql2": "^3.18.2",
36
+ "reflect-metadata": "^0.2.2",
37
+ "rxjs": "^7.8.1",
38
+ "sequelize": "^6.37.7",
39
+ "sequelize-typescript": "^2.1.6"
40
+ },
41
+ "devDependencies": {
42
+ "@eslint/eslintrc": "^3.2.0",
43
+ "@eslint/js": "^9.18.0",
44
+ "@nestjs/cli": "^11.0.0",
45
+ "@nestjs/schematics": "^11.0.0",
46
+ "@nestjs/testing": "^11.0.1",
47
+ "@types/express": "^5.0.0",
48
+ "@types/jest": "^30.0.0",
49
+ "@types/node": "^22.10.7",
50
+ "@types/sequelize": "^4.28.20",
51
+ "@types/supertest": "^6.0.2",
52
+ "eslint": "^9.18.0",
53
+ "eslint-config-prettier": "^10.0.1",
54
+ "eslint-plugin-prettier": "^5.2.2",
55
+ "globals": "^16.0.0",
56
+ "jest": "^30.0.0",
57
+ "prettier": "^3.4.2",
58
+ "source-map-support": "^0.5.21",
59
+ "supertest": "^7.0.0",
60
+ "ts-jest": "^29.2.5",
61
+ "ts-loader": "^9.5.2",
62
+ "ts-node": "^10.9.2",
63
+ "tsconfig-paths": "^4.2.0",
64
+ "typescript": "^5.7.3",
65
+ "typescript-eslint": "^8.20.0"
66
+ },
67
+ "jest": {
68
+ "moduleFileExtensions": [
69
+ "js",
70
+ "json",
71
+ "ts"
72
+ ],
73
+ "rootDir": "src",
74
+ "testRegex": ".*\\.spec\\.ts$",
75
+ "transform": {
76
+ "^.+\\.(t|j)s$": "ts-jest"
77
+ },
78
+ "collectCoverageFrom": [
79
+ "**/*.(t|j)s"
80
+ ],
81
+ "coverageDirectory": "../coverage",
82
+ "testEnvironment": "node"
83
+ }
84
+ }
@@ -0,0 +1,26 @@
1
+ import { Module } from '@nestjs/common';
2
+ import { getDbModels } from '../libs/tatayab-entities-library/src';
3
+ import { SequelizeModule } from '@nestjs/sequelize';
4
+ import { ConfigModule } from '@nestjs/config';
5
+
6
+ @Module({
7
+ imports: [
8
+ ConfigModule.forRoot({
9
+ isGlobal: true,
10
+ }),
11
+ SequelizeModule.forRoot({
12
+ dialect: 'mysql',
13
+ host: process.env.MYSQL_HOST,
14
+ database: process.env.MYSQL_DATABASE,
15
+ username: process.env.MYSQL_USER,
16
+ password: process.env.MYSQL_PASSWORD,
17
+ port: 3306,
18
+ autoLoadModels: true,
19
+ synchronize: true,
20
+ logging: false,
21
+ models: getDbModels(),
22
+ }),
23
+ ],
24
+ providers: [],
25
+ })
26
+ export class AppModule {}
@@ -0,0 +1,35 @@
1
+ require('dotenv').config();
2
+ module.exports = {
3
+ DEVELOPMENT: {
4
+ dialect: 'mysql',
5
+ host: process.env.MYSQL_HOST,
6
+ port: process.env.MYSQL_PORT,
7
+ username: process.env.MYSQL_USER,
8
+ password: process.env.MYSQL_PASS,
9
+ database: process.env.MYSQL_DATABASE,
10
+ },
11
+ LOCAL: {
12
+ dialect: 'mysql',
13
+ host: process.env.MYSQL_HOST,
14
+ port: process.env.MYSQL_PORT,
15
+ username: process.env.MYSQL_USER,
16
+ password: process.env.MYSQL_PASS,
17
+ database: process.env.MYSQL_DATABASE,
18
+ },
19
+ STAGING: {
20
+ dialect: 'mysql',
21
+ host: process.env.MYSQL_HOST,
22
+ port: process.env.MYSQL_PORT,
23
+ username: process.env.MYSQL_USER,
24
+ password: process.env.MYSQL_PASS,
25
+ database: process.env.MYSQL_DATABASE,
26
+ },
27
+ PRODUCTION: {
28
+ dialect: 'mysql',
29
+ host: process.env.MYSQL_HOST,
30
+ port: process.env.MYSQL_PORT,
31
+ username: process.env.MYSQL_USER,
32
+ password: process.env.MYSQL_PASS,
33
+ database: process.env.MYSQL_DATABASE,
34
+ },
35
+ };
package/src/main.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { NestFactory } from '@nestjs/core';
2
+ import { AppModule } from './app.module';
3
+
4
+ async function bootstrap() {
5
+ const app = await NestFactory.create(AppModule, { cors: true });
6
+ await app.listen(process.env.SERVER_PORT ?? 9004);
7
+ }
8
+ bootstrap();
@@ -0,0 +1,25 @@
1
+ import { Test, TestingModule } from '@nestjs/testing';
2
+ import { INestApplication } from '@nestjs/common';
3
+ import request from 'supertest';
4
+ import { App } from 'supertest/types';
5
+ import { AppModule } from './../src/app.module';
6
+
7
+ describe('AppController (e2e)', () => {
8
+ let app: INestApplication<App>;
9
+
10
+ beforeEach(async () => {
11
+ const moduleFixture: TestingModule = await Test.createTestingModule({
12
+ imports: [AppModule],
13
+ }).compile();
14
+
15
+ app = moduleFixture.createNestApplication();
16
+ await app.init();
17
+ });
18
+
19
+ it('/ (GET)', () => {
20
+ return request(app.getHttpServer())
21
+ .get('/')
22
+ .expect(200)
23
+ .expect('Hello World!');
24
+ });
25
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "moduleFileExtensions": ["js", "json", "ts"],
3
+ "rootDir": ".",
4
+ "testEnvironment": "node",
5
+ "testRegex": ".e2e-spec.ts$",
6
+ "transform": {
7
+ "^.+\\.(t|j)s$": "ts-jest"
8
+ }
9
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "nodenext",
4
+ "moduleResolution": "nodenext",
5
+ "resolvePackageJsonExports": true,
6
+ "esModuleInterop": true,
7
+ "isolatedModules": true,
8
+ "declaration": true,
9
+ "removeComments": true,
10
+ "emitDecoratorMetadata": true,
11
+ "experimentalDecorators": true,
12
+ "allowSyntheticDefaultImports": true,
13
+ "target": "ES2023",
14
+ "sourceMap": true,
15
+ "outDir": "./dist",
16
+ "baseUrl": "./",
17
+ "incremental": true,
18
+ "skipLibCheck": true,
19
+ "strictNullChecks": true,
20
+ "forceConsistentCasingInFileNames": true,
21
+ "noImplicitAny": false,
22
+ "strictBindCallApply": false,
23
+ "noFallthroughCasesInSwitch": false
24
+ }
25
+ }