namirasoft-field-node 1.3.4

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 (135) hide show
  1. package/dist/Application.d.ts +7 -0
  2. package/dist/Application.js +41 -0
  3. package/dist/Application.js.map +1 -0
  4. package/dist/controller/BaseEntityFieldController.d.ts +12 -0
  5. package/dist/controller/BaseEntityFieldController.js +16 -0
  6. package/dist/controller/BaseEntityFieldController.js.map +1 -0
  7. package/dist/controller/BaseEntityFieldControllerProps.d.ts +3 -0
  8. package/dist/controller/BaseEntityFieldControllerProps.js +3 -0
  9. package/dist/controller/BaseEntityFieldControllerProps.js.map +1 -0
  10. package/dist/controller/BaseEntityFieldControllerState.d.ts +3 -0
  11. package/dist/controller/BaseEntityFieldControllerState.js +3 -0
  12. package/dist/controller/BaseEntityFieldControllerState.js.map +1 -0
  13. package/dist/controller/entity_category/Create.d.ts +21 -0
  14. package/dist/controller/entity_category/Create.js +64 -0
  15. package/dist/controller/entity_category/Create.js.map +1 -0
  16. package/dist/controller/entity_category/Delete.d.ts +21 -0
  17. package/dist/controller/entity_category/Delete.js +63 -0
  18. package/dist/controller/entity_category/Delete.js.map +1 -0
  19. package/dist/controller/entity_category/Get.d.ts +22 -0
  20. package/dist/controller/entity_category/Get.js +65 -0
  21. package/dist/controller/entity_category/Get.js.map +1 -0
  22. package/dist/controller/entity_category/List.d.ts +27 -0
  23. package/dist/controller/entity_category/List.js +64 -0
  24. package/dist/controller/entity_category/List.js.map +1 -0
  25. package/dist/controller/entity_category/Update.d.ts +21 -0
  26. package/dist/controller/entity_category/Update.js +66 -0
  27. package/dist/controller/entity_category/Update.js.map +1 -0
  28. package/dist/controller/entity_field/Create.d.ts +21 -0
  29. package/dist/controller/entity_field/Create.js +66 -0
  30. package/dist/controller/entity_field/Create.js.map +1 -0
  31. package/dist/controller/entity_field/Delete.d.ts +21 -0
  32. package/dist/controller/entity_field/Delete.js +63 -0
  33. package/dist/controller/entity_field/Delete.js.map +1 -0
  34. package/dist/controller/entity_field/Get.d.ts +22 -0
  35. package/dist/controller/entity_field/Get.js +65 -0
  36. package/dist/controller/entity_field/Get.js.map +1 -0
  37. package/dist/controller/entity_field/List.d.ts +27 -0
  38. package/dist/controller/entity_field/List.js +64 -0
  39. package/dist/controller/entity_field/List.js.map +1 -0
  40. package/dist/controller/entity_field/Update.d.ts +21 -0
  41. package/dist/controller/entity_field/Update.js +68 -0
  42. package/dist/controller/entity_field/Update.js.map +1 -0
  43. package/dist/controller/entity_tag/Create.d.ts +21 -0
  44. package/dist/controller/entity_tag/Create.js +66 -0
  45. package/dist/controller/entity_tag/Create.js.map +1 -0
  46. package/dist/controller/entity_tag/Delete.d.ts +21 -0
  47. package/dist/controller/entity_tag/Delete.js +63 -0
  48. package/dist/controller/entity_tag/Delete.js.map +1 -0
  49. package/dist/controller/entity_tag/Get.d.ts +22 -0
  50. package/dist/controller/entity_tag/Get.js +65 -0
  51. package/dist/controller/entity_tag/Get.js.map +1 -0
  52. package/dist/controller/entity_tag/List.d.ts +27 -0
  53. package/dist/controller/entity_tag/List.js +64 -0
  54. package/dist/controller/entity_tag/List.js.map +1 -0
  55. package/dist/controller/entity_tag/Update.d.ts +21 -0
  56. package/dist/controller/entity_tag/Update.js +68 -0
  57. package/dist/controller/entity_tag/Update.js.map +1 -0
  58. package/dist/database/DatabaseTables.d.ts +13 -0
  59. package/dist/database/DatabaseTables.js +33 -0
  60. package/dist/database/DatabaseTables.js.map +1 -0
  61. package/dist/database/attributes/EntityCategoryAttributes.d.ts +3 -0
  62. package/dist/database/attributes/EntityCategoryAttributes.js +11 -0
  63. package/dist/database/attributes/EntityCategoryAttributes.js.map +1 -0
  64. package/dist/database/attributes/EntityFieldAttributes.d.ts +3 -0
  65. package/dist/database/attributes/EntityFieldAttributes.js +13 -0
  66. package/dist/database/attributes/EntityFieldAttributes.js.map +1 -0
  67. package/dist/database/attributes/EntityTagAttributes.d.ts +3 -0
  68. package/dist/database/attributes/EntityTagAttributes.js +13 -0
  69. package/dist/database/attributes/EntityTagAttributes.js.map +1 -0
  70. package/dist/database/model/EntityCategoryModel.d.ts +7 -0
  71. package/dist/database/model/EntityCategoryModel.js +9 -0
  72. package/dist/database/model/EntityCategoryModel.js.map +1 -0
  73. package/dist/database/model/EntityFieldModel.d.ts +9 -0
  74. package/dist/database/model/EntityFieldModel.js +8 -0
  75. package/dist/database/model/EntityFieldModel.js.map +1 -0
  76. package/dist/database/model/EntityTagModel.d.ts +9 -0
  77. package/dist/database/model/EntityTagModel.js +8 -0
  78. package/dist/database/model/EntityTagModel.js.map +1 -0
  79. package/dist/database/table/EntityCategoryTable.d.ts +17 -0
  80. package/dist/database/table/EntityCategoryTable.js +65 -0
  81. package/dist/database/table/EntityCategoryTable.js.map +1 -0
  82. package/dist/database/table/EntityFieldTable.d.ts +17 -0
  83. package/dist/database/table/EntityFieldTable.js +69 -0
  84. package/dist/database/table/EntityFieldTable.js.map +1 -0
  85. package/dist/database/table/EntityTagTable.d.ts +17 -0
  86. package/dist/database/table/EntityTagTable.js +69 -0
  87. package/dist/database/table/EntityTagTable.js.map +1 -0
  88. package/dist/enum/EntityCategoryNames.d.ts +3 -0
  89. package/dist/enum/EntityCategoryNames.js +9 -0
  90. package/dist/enum/EntityCategoryNames.js.map +1 -0
  91. package/dist/enum/EntityFieldNames.d.ts +3 -0
  92. package/dist/enum/EntityFieldNames.js +9 -0
  93. package/dist/enum/EntityFieldNames.js.map +1 -0
  94. package/dist/enum/EntityTagNames.d.ts +3 -0
  95. package/dist/enum/EntityTagNames.js +9 -0
  96. package/dist/enum/EntityTagNames.js.map +1 -0
  97. package/dist/index.d.ts +1 -0
  98. package/dist/index.js +18 -0
  99. package/dist/index.js.map +1 -0
  100. package/logo.png +0 -0
  101. package/package.json +28 -0
  102. package/src/Application.ts +43 -0
  103. package/src/controller/BaseEntityFieldController.ts +22 -0
  104. package/src/controller/BaseEntityFieldControllerProps.ts +5 -0
  105. package/src/controller/BaseEntityFieldControllerState.ts +5 -0
  106. package/src/controller/entity_category/Create.ts +52 -0
  107. package/src/controller/entity_category/Delete.ts +48 -0
  108. package/src/controller/entity_category/Get.ts +51 -0
  109. package/src/controller/entity_category/List.ts +50 -0
  110. package/src/controller/entity_category/Update.ts +53 -0
  111. package/src/controller/entity_field/Create.ts +55 -0
  112. package/src/controller/entity_field/Delete.ts +48 -0
  113. package/src/controller/entity_field/Get.ts +51 -0
  114. package/src/controller/entity_field/List.ts +50 -0
  115. package/src/controller/entity_field/Update.ts +57 -0
  116. package/src/controller/entity_tag/Create.ts +55 -0
  117. package/src/controller/entity_tag/Delete.ts +48 -0
  118. package/src/controller/entity_tag/Get.ts +51 -0
  119. package/src/controller/entity_tag/List.ts +50 -0
  120. package/src/controller/entity_tag/Update.ts +57 -0
  121. package/src/database/DatabaseTables.ts +40 -0
  122. package/src/database/attributes/EntityCategoryAttributes.ts +12 -0
  123. package/src/database/attributes/EntityFieldAttributes.ts +14 -0
  124. package/src/database/attributes/EntityTagAttributes.ts +14 -0
  125. package/src/database/model/EntityCategoryModel.ts +9 -0
  126. package/src/database/model/EntityFieldModel.ts +11 -0
  127. package/src/database/model/EntityTagModel.ts +11 -0
  128. package/src/database/table/EntityCategoryTable.ts +63 -0
  129. package/src/database/table/EntityFieldTable.ts +67 -0
  130. package/src/database/table/EntityTagTable.ts +67 -0
  131. package/src/enum/EntityCategoryNames.ts +4 -0
  132. package/src/enum/EntityFieldNames.ts +4 -0
  133. package/src/enum/EntityTagNames.ts +4 -0
  134. package/src/index.ts +1 -0
  135. package/tsconfig.json +42 -0
@@ -0,0 +1,51 @@
1
+ import { HTTPMethod, ObjectService } from "namirasoft-core";
2
+ import { BaseEntityFieldController } from "../BaseEntityFieldController";
3
+ import { EntityFieldModel } from "../../database/model/EntityFieldModel";
4
+ import { StringSchema, BaseVariableSchema } from "namirasoft-schema";
5
+
6
+ export class Get extends BaseEntityFieldController<EntityFieldModel>
7
+ {
8
+ override getInfo()
9
+ {
10
+ return {
11
+ name: "Get",
12
+ tag: "Field",
13
+ method: HTTPMethod.GET,
14
+ path: "/field/{id}",
15
+ summary: "Returns an field by id."
16
+ };
17
+ }
18
+ override async getParametersSchema()
19
+ {
20
+ return [new BaseVariableSchema("id", new StringSchema(true))];
21
+ }
22
+ override async getQueriesSchema()
23
+ {
24
+ return [];
25
+ }
26
+ override async getBodySchema()
27
+ {
28
+ return null;
29
+ }
30
+ override async getOutputSchema()
31
+ {
32
+ return this.tables.entity_field.getSchemaByName(true);
33
+ }
34
+ override async getState()
35
+ {
36
+ return {
37
+ check_auth: true,
38
+ auth_optional: false
39
+ };
40
+ }
41
+ override async handle()
42
+ {
43
+ let session = await this.props.getSession();
44
+ let user_id = session.user_id;
45
+
46
+ let id = new ObjectService(this.req.params.id).getString();
47
+
48
+ let ans = await this.tables.entity_field.get(user_id, id, null);
49
+ return await this.tables.entity_field.secure(ans);
50
+ }
51
+ }
@@ -0,0 +1,50 @@
1
+ import { HTTPMethod } from "namirasoft-core";
2
+ import { BaseEntityFieldController } from "../BaseEntityFieldController";
3
+ import { EntityFieldModel } from "../../database/model/EntityFieldModel";
4
+ import { NSControllerList } from "namirasoft-site-node";
5
+
6
+ export class List extends BaseEntityFieldController<{ rows: EntityFieldModel[], count: number }>
7
+ {
8
+ override getInfo()
9
+ {
10
+ return {
11
+ name: "List",
12
+ tag: "Field",
13
+ method: HTTPMethod.GET,
14
+ path: "/field/list",
15
+ summary: "Returns all fields."
16
+ };
17
+ }
18
+ override async getParametersSchema()
19
+ {
20
+ return [];
21
+ }
22
+ override async getQueriesSchema()
23
+ {
24
+ return NSControllerList.getQueriesSchema();
25
+ }
26
+ override async getBodySchema()
27
+ {
28
+ return null;
29
+ }
30
+ override async getOutputSchema()
31
+ {
32
+ return NSControllerList.getOutputSchema(this.tables.entity_field.getArraySchemaByName(true));
33
+ }
34
+ override async getState()
35
+ {
36
+ return {
37
+ check_auth: true,
38
+ auth_optional: false
39
+ };
40
+ }
41
+ override async handle()
42
+ {
43
+ let session = await this.props.getSession();
44
+ let user_id = session.user_id;
45
+
46
+ let { filters, page, size } = NSControllerList.handle_GetQueries(this.req);
47
+
48
+ return await this.tables.entity_field.list({ user_id }, filters, page, size, {}, null);
49
+ }
50
+ }
@@ -0,0 +1,57 @@
1
+ import { HTTPMethod, ObjectService } from "namirasoft-core";
2
+ import { BaseEntityFieldController } from "../BaseEntityFieldController";
3
+ import { StringSchema, BaseVariableSchema } from "namirasoft-schema";
4
+ import { EntityFieldNames } from "../../enum/EntityFieldNames";
5
+ export class Update extends BaseEntityFieldController<string>
6
+ {
7
+ override getInfo()
8
+ {
9
+ return {
10
+ name: "Update",
11
+ tag: "Field",
12
+ method: HTTPMethod.PUT,
13
+ path: "/field/{id}",
14
+ summary: "Updates an field"
15
+ };
16
+ }
17
+ override async getParametersSchema()
18
+ {
19
+ return [new BaseVariableSchema("id", new StringSchema(true))];
20
+ }
21
+ override async getQueriesSchema()
22
+ {
23
+ return [];
24
+ }
25
+ override async getBodySchema()
26
+ {
27
+ return this.tables.entity_field.getSchemaByName(true, EntityFieldNames.EntityFieldInput);
28
+ }
29
+ override async getOutputSchema()
30
+ {
31
+ return this.tables.entity_field.getSchemaByName(true);
32
+ }
33
+ override async getState()
34
+ {
35
+ return {
36
+ check_auth: true,
37
+ auth_optional: false
38
+ };
39
+ }
40
+ override async handle()
41
+ {
42
+ let session = await this.props.getSession();
43
+
44
+ let id = new ObjectService(this.req.params.id).getString();
45
+
46
+ let field_id = new ObjectService(this.req.body.field_id).getString();
47
+ let value = new ObjectService(this.req.body.value).getString();
48
+ let description = new ObjectService(this.req.body.description).getString();
49
+
50
+ let ans = await this.tables.entity_field.update(session, id,
51
+ field_id,
52
+ value,
53
+ description,
54
+ null);
55
+ return await this.tables.entity_field.secure(ans);
56
+ }
57
+ }
@@ -0,0 +1,55 @@
1
+ import { HTTPMethod, ObjectService } from "namirasoft-core";
2
+ import { BaseEntityFieldController } from "../BaseEntityFieldController";
3
+ import { EntityTagModel } from "../../database/model/EntityTagModel";
4
+ import { EntityTagNames } from "../../enum/EntityTagNames";
5
+ export class Create extends BaseEntityFieldController<EntityTagModel>
6
+ {
7
+ override getInfo()
8
+ {
9
+ return {
10
+ name: "Create",
11
+ tag: "Tag",
12
+ method: HTTPMethod.POST,
13
+ path: "/tag",
14
+ summary: "Creates a new tag"
15
+ };
16
+ }
17
+ override async getParametersSchema()
18
+ {
19
+ return [];
20
+ }
21
+ override async getQueriesSchema()
22
+ {
23
+ return [];
24
+ }
25
+ override async getBodySchema()
26
+ {
27
+ return this.tables.entity_tag.getSchemaByName(true, EntityTagNames.EntityTagInput);
28
+ }
29
+ override async getOutputSchema()
30
+ {
31
+ return this.tables.entity_tag.getSchemaByName(true);
32
+ }
33
+ override async getState()
34
+ {
35
+ return {
36
+ check_auth: true,
37
+ auth_optional: false
38
+ };
39
+ }
40
+ override async handle()
41
+ {
42
+ let session = await this.props.getSession();
43
+
44
+ let name = new ObjectService(this.req.body.name).getString();
45
+ let value = new ObjectService(this.req.body.value).getString();
46
+ let description = new ObjectService(this.req.body.description).getString();
47
+
48
+ let ans = await this.tables.entity_tag.create(session,
49
+ name,
50
+ value,
51
+ description,
52
+ null);
53
+ return await this.tables.entity_tag.secure(ans);
54
+ }
55
+ }
@@ -0,0 +1,48 @@
1
+ import { HTTPMethod, ObjectService } from "namirasoft-core";
2
+ import { BaseEntityFieldController } from "../BaseEntityFieldController";
3
+ import { StringSchema, BaseVariableSchema } from "namirasoft-schema";
4
+
5
+ export class Delete extends BaseEntityFieldController<void>
6
+ {
7
+ override getInfo()
8
+ {
9
+ return {
10
+ name: "Delete",
11
+ tag: "Tag",
12
+ method: HTTPMethod.DELETE,
13
+ path: "/tag/{id}",
14
+ summary: "Deletes an tag by id."
15
+ };
16
+ }
17
+ override async getParametersSchema()
18
+ {
19
+ return [new BaseVariableSchema("id", new StringSchema(true))];
20
+ }
21
+ override async getQueriesSchema()
22
+ {
23
+ return [];
24
+ }
25
+ override async getBodySchema()
26
+ {
27
+ return null;
28
+ }
29
+ override async getOutputSchema()
30
+ {
31
+ return null;
32
+ }
33
+ override async getState()
34
+ {
35
+ return {
36
+ check_auth: true,
37
+ auth_optional: false
38
+ };
39
+ }
40
+ override async handle()
41
+ {
42
+ let session = await this.props.getSession();
43
+
44
+ let id = new ObjectService(this.req.params.id).getString();
45
+
46
+ await this.tables.entity_tag.delete(session, id, null);
47
+ }
48
+ }
@@ -0,0 +1,51 @@
1
+ import { HTTPMethod, ObjectService } from "namirasoft-core";
2
+ import { BaseEntityFieldController } from "../BaseEntityFieldController";
3
+ import { EntityTagModel } from "../../database/model/EntityTagModel";
4
+ import { StringSchema, BaseVariableSchema } from "namirasoft-schema";
5
+
6
+ export class Get extends BaseEntityFieldController<EntityTagModel>
7
+ {
8
+ override getInfo()
9
+ {
10
+ return {
11
+ name: "Get",
12
+ tag: "Tag",
13
+ method: HTTPMethod.GET,
14
+ path: "/tag/{id}",
15
+ summary: "Returns an tag by id."
16
+ };
17
+ }
18
+ override async getParametersSchema()
19
+ {
20
+ return [new BaseVariableSchema("id", new StringSchema(true))];
21
+ }
22
+ override async getQueriesSchema()
23
+ {
24
+ return [];
25
+ }
26
+ override async getBodySchema()
27
+ {
28
+ return null;
29
+ }
30
+ override async getOutputSchema()
31
+ {
32
+ return this.tables.entity_tag.getSchemaByName(true);
33
+ }
34
+ override async getState()
35
+ {
36
+ return {
37
+ check_auth: true,
38
+ auth_optional: false
39
+ };
40
+ }
41
+ override async handle()
42
+ {
43
+ let session = await this.props.getSession();
44
+ let user_id = session.user_id;
45
+
46
+ let id = new ObjectService(this.req.params.id).getString();
47
+
48
+ let ans = await this.tables.entity_tag.get(user_id, id, null);
49
+ return await this.tables.entity_tag.secure(ans);
50
+ }
51
+ }
@@ -0,0 +1,50 @@
1
+ import { HTTPMethod } from "namirasoft-core";
2
+ import { BaseEntityFieldController } from "../BaseEntityFieldController";
3
+ import { EntityTagModel } from "../../database/model/EntityTagModel";
4
+ import { NSControllerList } from "namirasoft-site-node";
5
+
6
+ export class List extends BaseEntityFieldController<{ rows: EntityTagModel[], count: number }>
7
+ {
8
+ override getInfo()
9
+ {
10
+ return {
11
+ name: "List",
12
+ tag: "Tag",
13
+ method: HTTPMethod.GET,
14
+ path: "/tag/list",
15
+ summary: "Returns all tags."
16
+ };
17
+ }
18
+ override async getParametersSchema()
19
+ {
20
+ return [];
21
+ }
22
+ override async getQueriesSchema()
23
+ {
24
+ return NSControllerList.getQueriesSchema();
25
+ }
26
+ override async getBodySchema()
27
+ {
28
+ return null;
29
+ }
30
+ override async getOutputSchema()
31
+ {
32
+ return NSControllerList.getOutputSchema(this.tables.entity_tag.getArraySchemaByName(true));
33
+ }
34
+ override async getState()
35
+ {
36
+ return {
37
+ check_auth: true,
38
+ auth_optional: false
39
+ };
40
+ }
41
+ override async handle()
42
+ {
43
+ let session = await this.props.getSession();
44
+ let user_id = session.user_id;
45
+
46
+ let { filters, page, size } = NSControllerList.handle_GetQueries(this.req);
47
+
48
+ return await this.tables.entity_tag.list({ user_id }, filters, page, size, {}, null);
49
+ }
50
+ }
@@ -0,0 +1,57 @@
1
+ import { HTTPMethod, ObjectService } from "namirasoft-core";
2
+ import { BaseEntityFieldController } from "../BaseEntityFieldController";
3
+ import { StringSchema, BaseVariableSchema } from "namirasoft-schema";
4
+ import { EntityTagNames } from "../../enum/EntityTagNames";
5
+ export class Update extends BaseEntityFieldController<string>
6
+ {
7
+ override getInfo()
8
+ {
9
+ return {
10
+ name: "Update",
11
+ tag: "Tag",
12
+ method: HTTPMethod.PUT,
13
+ path: "/tag/{id}",
14
+ summary: "Updates a tag"
15
+ };
16
+ }
17
+ override async getParametersSchema()
18
+ {
19
+ return [new BaseVariableSchema("id", new StringSchema(true))];
20
+ }
21
+ override async getQueriesSchema()
22
+ {
23
+ return [];
24
+ }
25
+ override async getBodySchema()
26
+ {
27
+ return this.tables.entity_tag.getSchemaByName(true, EntityTagNames.EntityTagInput);
28
+ }
29
+ override async getOutputSchema()
30
+ {
31
+ return this.tables.entity_tag.getSchemaByName(true);
32
+ }
33
+ override async getState()
34
+ {
35
+ return {
36
+ check_auth: true,
37
+ auth_optional: false
38
+ };
39
+ }
40
+ override async handle()
41
+ {
42
+ let session = await this.props.getSession();
43
+
44
+ let id = new ObjectService(this.req.params.id).getString();
45
+
46
+ let name = new ObjectService(this.req.body.name).getString();
47
+ let value = new ObjectService(this.req.body.value).getString();
48
+ let description = new ObjectService(this.req.body.description).getString();
49
+
50
+ let ans = await this.tables.entity_tag.update(session, id,
51
+ name,
52
+ value,
53
+ description,
54
+ null);
55
+ return await this.tables.entity_tag.secure(ans);
56
+ }
57
+ }
@@ -0,0 +1,40 @@
1
+ import { BaseMySqlDatabase, BaseSequelizeModel } from "namirasoft-node-mysql";
2
+ import { EntityCategoryTable } from "./table/EntityCategoryTable";
3
+ import { EntityFieldTable } from "./table/EntityFieldTable";
4
+ import { EntityTagTable } from "./table/EntityTagTable";
5
+ import { NSABaseApplication } from "namirasoft-account-node";
6
+ import { EntityTagAttributes } from "./attributes/EntityTagAttributes";
7
+ import { EntityFieldAttributes } from "./attributes/EntityFieldAttributes";
8
+ import { EntityCategoryAttributes } from "./attributes/EntityCategoryAttributes";
9
+ import { ModelCtor } from 'sequelize';
10
+
11
+ export class DatabaseTables<Database extends BaseMySqlDatabase>
12
+ {
13
+ entity_category: EntityCategoryTable<Database>;
14
+ entity_field: EntityFieldTable<Database>;
15
+ entity_tag: EntityTagTable<Database>;
16
+ constructor(app: NSABaseApplication<Database>, database: Database)
17
+ {
18
+ this.entity_category = new EntityCategoryTable<Database>(app, database);
19
+ this.entity_field = new EntityFieldTable<Database>(app, database);
20
+ this.entity_tag = new EntityTagTable<Database>(app, database);
21
+ }
22
+ init<M extends BaseSequelizeModel>(model: ModelCtor<M>)
23
+ {
24
+ let name = model.name;
25
+ this.entity_category.define(name + "_category", EntityCategoryAttributes);
26
+ this.entity_field.define(name + "_field", EntityFieldAttributes);
27
+ this.entity_tag.define(name + "_tag", EntityTagAttributes);
28
+
29
+ // set foreignKeys
30
+ this.entity_tag.model.belongsTo(model, {
31
+ foreignKey: { name: "entity_id", allowNull: false },
32
+ });
33
+ this.entity_field.model.belongsTo(model, {
34
+ foreignKey: { name: "entity_id", allowNull: false },
35
+ });
36
+ this.entity_category.model.belongsTo(model, {
37
+ foreignKey: { name: "entity_id", allowNull: false },
38
+ });
39
+ }
40
+ }
@@ -0,0 +1,12 @@
1
+ import { DataTypes, Attributes, ModelAttributes } from "sequelize";
2
+ import { EntityCategoryModel } from "../model/EntityCategoryModel";
3
+
4
+ export let EntityCategoryAttributes: ModelAttributes<
5
+ EntityCategoryModel,
6
+ Attributes<EntityCategoryModel>
7
+ > = {
8
+ id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
9
+ user_id: { type: DataTypes.CHAR(20), allowNull: false },
10
+ entity_id: { type: DataTypes.CHAR(20), allowNull: false },
11
+ category_id: { type: DataTypes.CHAR(20), allowNull: false }
12
+ };
@@ -0,0 +1,14 @@
1
+ import { DataTypes, Attributes, ModelAttributes } from "sequelize";
2
+ import { EntityFieldModel } from "../model/EntityFieldModel";
3
+
4
+ export let EntityFieldAttributes: ModelAttributes<
5
+ EntityFieldModel,
6
+ Attributes<EntityFieldModel>
7
+ > = {
8
+ id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
9
+ user_id: { type: DataTypes.CHAR(20), allowNull: false },
10
+ entity_id: { type: DataTypes.CHAR(20), allowNull: false },
11
+ field_id: { type: DataTypes.CHAR(20), allowNull: false },
12
+ value: { type: DataTypes.TEXT, allowNull: false },
13
+ description: { type: DataTypes.TEXT, allowNull: false },
14
+ };
@@ -0,0 +1,14 @@
1
+ import { DataTypes, Attributes, ModelAttributes } from "sequelize";
2
+ import { EntityTagModel } from "../model/EntityTagModel";
3
+
4
+ export let EntityTagAttributes: ModelAttributes<
5
+ EntityTagModel,
6
+ Attributes<EntityTagModel>
7
+ > = {
8
+ id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
9
+ user_id: { type: DataTypes.CHAR(20), allowNull: false },
10
+ entity_id: { type: DataTypes.CHAR(20), allowNull: false },
11
+ name: { type: DataTypes.STRING, allowNull: false },
12
+ value: { type: DataTypes.TEXT, allowNull: false },
13
+ description: { type: DataTypes.TEXT, allowNull: false }
14
+ };
@@ -0,0 +1,9 @@
1
+ import { BaseSequelizeModel } from "namirasoft-node-mysql";
2
+
3
+ export class EntityCategoryModel extends BaseSequelizeModel
4
+ {
5
+ id!: number;
6
+ user_id!: string;
7
+ entity_id!: string;
8
+ category_id!: string;
9
+ };
@@ -0,0 +1,11 @@
1
+ import { BaseSequelizeModel } from "namirasoft-node-mysql";
2
+
3
+ export class EntityFieldModel extends BaseSequelizeModel
4
+ {
5
+ id!: number;
6
+ user_id!: string;
7
+ entity_id!: string;
8
+ field_id!: string;
9
+ value!: string;
10
+ description!: string;
11
+ }
@@ -0,0 +1,11 @@
1
+ import { BaseSequelizeModel } from "namirasoft-node-mysql";
2
+
3
+ export class EntityTagModel extends BaseSequelizeModel
4
+ {
5
+ id!: number;
6
+ user_id!: string;
7
+ entity_id!: string;
8
+ name!: string;
9
+ value!: string;
10
+ description!: string;
11
+ }
@@ -0,0 +1,63 @@
1
+ import { BaseMySqlDatabase, BaseSequelizeTable } from "namirasoft-node-mysql";
2
+ import { Transaction } from "sequelize";
3
+ import { EntityCategoryModel } from "../model/EntityCategoryModel";
4
+ import { ObjectSchema } from "namirasoft-schema";
5
+ import { SessionRow } from "namirasoft-account";
6
+ import { EntityCategoryNames } from "../../enum/EntityCategoryNames";
7
+ import { NSABaseApplication } from "namirasoft-account-node";
8
+
9
+ export class EntityCategoryTable<Database extends BaseMySqlDatabase> extends BaseSequelizeTable<Database, EntityCategoryModel>
10
+ {
11
+ public app: NSABaseApplication<Database>;
12
+ constructor(app: NSABaseApplication<Database>, database: Database)
13
+ {
14
+ super(database);
15
+ this.app = app;
16
+ }
17
+ override getReadOnlyColumns()
18
+ {
19
+ return ["id", "user_id", "entity_id"];
20
+ }
21
+ override getSchemaNames(): string[]
22
+ {
23
+ return Object.keys(EntityCategoryNames);
24
+ }
25
+ protected override setSchemaByName(schema: ObjectSchema): void
26
+ {
27
+ schema.delReadOnly(true);
28
+ }
29
+ async get(user_id: string, id: string, trx: Transaction | null): Promise<EntityCategoryModel | null>
30
+ {
31
+ return await this.find({ where: { user_id, id }, }, trx);
32
+ }
33
+ async create(session: SessionRow, category_id: string, trx: Transaction | null): Promise<EntityCategoryModel>
34
+ {
35
+ return this.app.onHistoryCreate(this, session, async () =>
36
+ {
37
+ return await this.model.create({
38
+ user_id: session.user_id,
39
+ category_id,
40
+ }, { transaction: trx });
41
+ });
42
+ }
43
+ async update(session: SessionRow, id: string, category_id: string, trx: Transaction | null): Promise<EntityCategoryModel>
44
+ {
45
+ return await this.app.onHistoryUpdate(this, session, async () =>
46
+ {
47
+ return await this.find({ where: { user_id: session.user_id, id } }, trx);
48
+ }, async (item) =>
49
+ {
50
+ item.category_id = category_id;
51
+ return await item.save({ transaction: trx });
52
+ });
53
+ }
54
+ async delete(session: SessionRow, id: string, trx: Transaction | null): Promise<void>
55
+ {
56
+ await this.app.onHistoryDelete(this, session, async () =>
57
+ {
58
+ let item = await this.find({ where: { user_id: session.user_id, id } }, trx);
59
+ await item.destroy({ transaction: trx });
60
+ return item;
61
+ });
62
+ }
63
+ }
@@ -0,0 +1,67 @@
1
+ import { BaseMySqlDatabase, BaseSequelizeTable } from "namirasoft-node-mysql";
2
+ import { Transaction } from "sequelize";
3
+ import { EntityFieldModel } from "../model/EntityFieldModel";
4
+ import { ObjectSchema } from "namirasoft-schema";
5
+ import { SessionRow } from "namirasoft-account";
6
+ import { EntityFieldNames } from "../../enum/EntityFieldNames";
7
+ import { NSABaseApplication } from "namirasoft-account-node";
8
+
9
+ export class EntityFieldTable<Database extends BaseMySqlDatabase> extends BaseSequelizeTable<Database, EntityFieldModel>
10
+ {
11
+ public app: NSABaseApplication<Database>;
12
+ constructor(app: NSABaseApplication<Database>, database: Database)
13
+ {
14
+ super(database);
15
+ this.app = app;
16
+ }
17
+ override getReadOnlyColumns()
18
+ {
19
+ return ["id", "user_id", "entity_id"];
20
+ }
21
+ override getSchemaNames(): string[]
22
+ {
23
+ return Object.keys(EntityFieldNames);
24
+ }
25
+ protected override setSchemaByName(schema: ObjectSchema): void
26
+ {
27
+ schema.delReadOnly(true);
28
+ }
29
+ async get(user_id: string, id: string, trx: Transaction | null): Promise<EntityFieldModel | null>
30
+ {
31
+ return await this.find({ where: { user_id, id }, }, trx);
32
+ }
33
+ async create(session: SessionRow, field_id: string, value: string, description: string, trx: Transaction | null): Promise<EntityFieldModel>
34
+ {
35
+ return this.app.onHistoryCreate(this, session, async () =>
36
+ {
37
+ return await this.model.create({
38
+ user_id: session.user_id,
39
+ field_id,
40
+ value,
41
+ description,
42
+ }, { transaction: trx });
43
+ });
44
+ }
45
+ async update(session: SessionRow, id: string, field_id: string, value: string, description: string, trx: Transaction | null): Promise<EntityFieldModel>
46
+ {
47
+ return await this.app.onHistoryUpdate(this, session, async () =>
48
+ {
49
+ return await this.find({ where: { user_id: session.user_id, id } }, trx);
50
+ }, async (item) =>
51
+ {
52
+ item.field_id = field_id;
53
+ item.value = value;
54
+ item.description = description;
55
+ return await item.save({ transaction: trx });
56
+ });
57
+ }
58
+ async delete(session: SessionRow, id: string, trx: Transaction | null): Promise<void>
59
+ {
60
+ await this.app.onHistoryDelete(this, session, async () =>
61
+ {
62
+ let item = await this.find({ where: { user_id: session.user_id, id } }, trx);
63
+ await item.destroy({ transaction: trx });
64
+ return item;
65
+ });
66
+ }
67
+ }