diff --git a/database/migrations/.snapshot-negareh.json b/database/migrations/.snapshot-negareh.json new file mode 100644 index 0000000..a4b9d74 --- /dev/null +++ b/database/migrations/.snapshot-negareh.json @@ -0,0 +1,3480 @@ +{ + "namespaces": [ + "public" + ], + "name": "public", + "tables": [ + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "parent_id": { + "name": "parent_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "title": { + "name": "title", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "true", + "mappedType": "boolean" + }, + "avatar_url": { + "name": "avatar_url", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, + "order": { + "name": "order", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + } + }, + "name": "categories", + "schema": "public", + "indexes": [ + { + "keyName": "categories_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "categories_parent_id_foreign": { + "constraintName": "categories_parent_id_foreign", + "columnNames": [ + "parent_id" + ], + "localTableName": "public.categories", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.categories", + "deleteRule": "set null", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "enumItems": [ + "product", + "print" + ], + "mappedType": "enum" + }, + "entity_id": { + "name": "entity_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "name": { + "name": "name", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "type": { + "name": "type", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "enumItems": [ + "text", + "textarea", + "number", + "select", + "radio", + "checkbox", + "date" + ], + "mappedType": "enum" + }, + "is_required": { + "name": "is_required", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "multiple": { + "name": "multiple", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "order": { + "name": "order", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + } + }, + "name": "field", + "schema": "public", + "indexes": [ + { + "keyName": "field_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {}, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "value": { + "name": "value", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "field_id": { + "name": "field_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "order": { + "name": "order", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + } + }, + "name": "field_option", + "schema": "public", + "indexes": [ + { + "keyName": "field_option_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "field_option_field_id_foreign": { + "constraintName": "field_option_field_id_foreign", + "columnNames": [ + "field_id" + ], + "localTableName": "public.field_option", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.field", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "name": { + "name": "name", + "type": "varchar(100)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 100, + "mappedType": "string" + } + }, + "name": "learning_categories", + "schema": "public", + "indexes": [ + { + "columnNames": [ + "name" + ], + "composite": false, + "keyName": "learning_categories_name_unique", + "constraint": true, + "primary": false, + "unique": true + }, + { + "keyName": "learning_categories_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {}, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "title": { + "name": "title", + "type": "varchar(200)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 200, + "mappedType": "string" + }, + "description": { + "name": "description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "cover_url": { + "name": "cover_url", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "video_url": { + "name": "video_url", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "video_duration": { + "name": "video_duration", + "type": "varchar(200)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 200, + "mappedType": "string" + }, + "category_id": { + "name": "category_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + } + }, + "name": "learnings", + "schema": "public", + "indexes": [ + { + "keyName": "learnings_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "learnings_category_id_foreign": { + "constraintName": "learnings_category_id_foreign", + "columnNames": [ + "category_id" + ], + "localTableName": "public.learnings", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.learning_categories", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "fileds": { + "name": "fileds", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + } + }, + "name": "prints", + "schema": "public", + "indexes": [ + { + "keyName": "prints_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {}, + "nativeEnums": {} + }, + { + "columns": { + "phone": { + "name": "phone", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "code": { + "name": "code", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "mappedType": "datetime" + } + }, + "name": "otp", + "schema": "public", + "indexes": [ + { + "keyName": "otp_phone_index", + "columnNames": [ + "phone" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, + { + "keyName": "otp_pkey", + "columnNames": [ + "phone" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {}, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "name": { + "name": "name", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "enumItems": [ + "manage_products", + "manage_categories", + "view_requests", + "delete_request", + "update_request", + "view_invoices", + "create_invoice", + "update_invoice", + "delete_invoice", + "view_all_invoiced_orders", + "view_my_assigned_invoiced_requests", + "view_orders", + "view_assigned_orders", + "create_order", + "update_order", + "assign_designer", + "delete_order", + "manage_admins", + "manage_roles", + "manage_users", + "manage_payments", + "manage_settings", + "manage_form_builder", + "create_print", + "view_print", + "manage_learnings", + "manage_criticisms" + ], + "mappedType": "enum" + }, + "title": { + "name": "title", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + } + }, + "name": "permissions", + "schema": "public", + "indexes": [ + { + "keyName": "permissions_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {}, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "title": { + "name": "title", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "order": { + "name": "order", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + } + }, + "name": "print", + "schema": "public", + "indexes": [ + { + "keyName": "print_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {}, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "category_id": { + "name": "category_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "title": { + "name": "title", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "desc": { + "name": "desc", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "quantities": { + "name": "quantities", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "link_url": { + "name": "link_url", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "true", + "mappedType": "boolean" + }, + "images": { + "name": "images", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "order": { + "name": "order", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "integer" + } + }, + "name": "products", + "schema": "public", + "indexes": [ + { + "keyName": "products_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "products_category_id_foreign": { + "constraintName": "products_category_id_foreign", + "columnNames": [ + "category_id" + ], + "localTableName": "public.products", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.categories", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "hashed_token": { + "name": "hashed_token", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "owner_id": { + "name": "owner_id", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "type": { + "name": "type", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "enumItems": [ + "user", + "admin" + ], + "mappedType": "enum" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "mappedType": "datetime" + } + }, + "name": "refreshtokens", + "schema": "public", + "indexes": [ + { + "keyName": "refreshtokens_hashed_token_index", + "columnNames": [ + "hashed_token" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, + { + "keyName": "refreshtokens_pkey", + "columnNames": [ + "hashed_token" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {}, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "name": { + "name": "name", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "title": { + "name": "title", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "is_system": { + "name": "is_system", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + } + }, + "name": "roles", + "schema": "public", + "indexes": [ + { + "columnNames": [ + "name" + ], + "composite": false, + "keyName": "roles_name_unique", + "constraint": true, + "primary": false, + "unique": true + }, + { + "keyName": "roles_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {}, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "first_name": { + "name": "first_name", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, + "last_name": { + "name": "last_name", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, + "phone": { + "name": "phone", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "role_id": { + "name": "role_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + } + }, + "name": "admins", + "schema": "public", + "indexes": [ + { + "columnNames": [ + "phone" + ], + "composite": false, + "keyName": "admins_phone_unique", + "constraint": true, + "primary": false, + "unique": true + }, + { + "keyName": "admins_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "admins_role_id_foreign": { + "constraintName": "admins_role_id_foreign", + "columnNames": [ + "role_id" + ], + "localTableName": "public.admins", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.roles", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "admin_id": { + "name": "admin_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "events": { + "name": "events", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + } + }, + "name": "notification_preferences", + "schema": "public", + "indexes": [ + { + "columnNames": [ + "admin_id" + ], + "composite": false, + "keyName": "notification_preferences_admin_id_unique", + "constraint": true, + "primary": false, + "unique": true + }, + { + "keyName": "notification_preferences_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "notification_preferences_admin_id_foreign": { + "constraintName": "notification_preferences_admin_id_foreign", + "columnNames": [ + "admin_id" + ], + "localTableName": "public.notification_preferences", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.admins", + "deleteRule": "cascade", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "role_id": { + "name": "role_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "permission_id": { + "name": "permission_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + } + }, + "name": "role_permissions", + "schema": "public", + "indexes": [ + { + "keyName": "role_permissions_pkey", + "columnNames": [ + "role_id", + "permission_id" + ], + "composite": true, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "role_permissions_role_id_foreign": { + "constraintName": "role_permissions_role_id_foreign", + "columnNames": [ + "role_id" + ], + "localTableName": "public.role_permissions", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.roles", + "updateRule": "cascade" + }, + "role_permissions_permission_id_foreign": { + "constraintName": "role_permissions_permission_id_foreign", + "columnNames": [ + "permission_id" + ], + "localTableName": "public.role_permissions", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.permissions", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "serial", + "unsigned": false, + "autoincrement": true, + "primary": true, + "nullable": false, + "mappedType": "integer" + }, + "phone": { + "name": "phone", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "mappedType": "datetime" + } + }, + "name": "sms_logs", + "schema": "public", + "indexes": [ + { + "keyName": "sms_logs_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {}, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "first_name": { + "name": "first_name", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, + "last_name": { + "name": "last_name", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, + "phone": { + "name": "phone", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "true", + "mappedType": "boolean" + }, + "gender": { + "name": "gender", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "default": "true", + "mappedType": "boolean" + }, + "max_credit": { + "name": "max_credit", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "integer" + }, + "addresse": { + "name": "addresse", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + } + }, + "name": "users", + "schema": "public", + "indexes": [ + { + "columnNames": [ + "phone" + ], + "composite": false, + "keyName": "users_phone_unique", + "constraint": true, + "primary": false, + "unique": true + }, + { + "keyName": "users_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {}, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "content": { + "name": "content", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "user_id": { + "name": "user_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "admin_id": { + "name": "admin_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "attachments": { + "name": "attachments", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "ref_id": { + "name": "ref_id", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "parent_id": { + "name": "parent_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "read_at": { + "name": "read_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + } + }, + "name": "ticket", + "schema": "public", + "indexes": [ + { + "keyName": "ticket_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "ticket_user_id_foreign": { + "constraintName": "ticket_user_id_foreign", + "columnNames": [ + "user_id" + ], + "localTableName": "public.ticket", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.users", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "ticket_admin_id_foreign": { + "constraintName": "ticket_admin_id_foreign", + "columnNames": [ + "admin_id" + ], + "localTableName": "public.ticket", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.admins", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "ticket_parent_id_foreign": { + "constraintName": "ticket_parent_id_foreign", + "columnNames": [ + "parent_id" + ], + "localTableName": "public.ticket", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.ticket", + "deleteRule": "set null", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "user_id": { + "name": "user_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "request_number": { + "name": "request_number", + "type": "serial", + "unsigned": true, + "autoincrement": true, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "status": { + "name": "status", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "'pending'", + "enumItems": [ + "pending", + "invoiced" + ], + "mappedType": "enum" + } + }, + "name": "requests", + "schema": "public", + "indexes": [ + { + "keyName": "requests_user_id_index", + "columnNames": [ + "user_id" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, + { + "keyName": "requests_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "requests_user_id_foreign": { + "constraintName": "requests_user_id_foreign", + "columnNames": [ + "user_id" + ], + "localTableName": "public.requests", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.users", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "product_id": { + "name": "product_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "attributes": { + "name": "attributes", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "request_id": { + "name": "request_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "quantity": { + "name": "quantity", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "description": { + "name": "description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "attachments": { + "name": "attachments", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + } + }, + "name": "request_items", + "schema": "public", + "indexes": [ + { + "keyName": "request_items_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "request_items_product_id_foreign": { + "constraintName": "request_items_product_id_foreign", + "columnNames": [ + "product_id" + ], + "localTableName": "public.request_items", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.products", + "updateRule": "cascade" + }, + "request_items_request_id_foreign": { + "constraintName": "request_items_request_id_foreign", + "columnNames": [ + "request_id" + ], + "localTableName": "public.request_items", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.requests", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "user_id": { + "name": "user_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "admin_id": { + "name": "admin_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "title": { + "name": "title", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "enumItems": [ + "newRequest", + "invoiced", + "newOrder", + "designerAssign", + "paymentSuccess", + "newCriticism" + ], + "mappedType": "enum" + }, + "content": { + "name": "content", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "seen_at": { + "name": "seen_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + } + }, + "name": "notifications", + "schema": "public", + "indexes": [ + { + "keyName": "notifications_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "notifications_user_id_foreign": { + "constraintName": "notifications_user_id_foreign", + "columnNames": [ + "user_id" + ], + "localTableName": "public.notifications", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.users", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "notifications_admin_id_foreign": { + "constraintName": "notifications_admin_id_foreign", + "columnNames": [ + "admin_id" + ], + "localTableName": "public.notifications", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.admins", + "deleteRule": "set null", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "user_id": { + "name": "user_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "learning_id": { + "name": "learning_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "watched_at": { + "name": "watched_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "CURRENT_TIMESTAMP", + "mappedType": "datetime" + } + }, + "name": "learning_progress", + "schema": "public", + "indexes": [ + { + "keyName": "learning_progress_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "learning_progress_user_id_foreign": { + "constraintName": "learning_progress_user_id_foreign", + "columnNames": [ + "user_id" + ], + "localTableName": "public.learning_progress", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.users", + "updateRule": "cascade" + }, + "learning_progress_learning_id_foreign": { + "constraintName": "learning_progress_learning_id_foreign", + "columnNames": [ + "learning_id" + ], + "localTableName": "public.learning_progress", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.learnings", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "user_id": { + "name": "user_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "request_id": { + "name": "request_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "invoice_number": { + "name": "invoice_number", + "type": "serial", + "unsigned": true, + "autoincrement": true, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "discount": { + "name": "discount", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + }, + "sub_total": { + "name": "sub_total", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + }, + "tax_amount": { + "name": "tax_amount", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + }, + "total": { + "name": "total", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + }, + "paid_amount": { + "name": "paid_amount", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "integer" + }, + "balance": { + "name": "balance", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "0", + "mappedType": "integer" + }, + "enable_tax": { + "name": "enable_tax", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "approval_deadline": { + "name": "approval_deadline", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "attachments": { + "name": "attachments", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "payment_method": { + "name": "payment_method", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, + "description": { + "name": "description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + } + }, + "name": "invoices", + "schema": "public", + "indexes": [ + { + "keyName": "invoices_user_id_index", + "columnNames": [ + "user_id" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, + { + "keyName": "invoices_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "invoices_user_id_foreign": { + "constraintName": "invoices_user_id_foreign", + "columnNames": [ + "user_id" + ], + "localTableName": "public.invoices", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.users", + "updateRule": "cascade" + }, + "invoices_request_id_foreign": { + "constraintName": "invoices_request_id_foreign", + "columnNames": [ + "request_id" + ], + "localTableName": "public.invoices", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.requests", + "deleteRule": "set null", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "invoice_id": { + "name": "invoice_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "creator_id": { + "name": "creator_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "amount": { + "name": "amount", + "type": "numeric(10,0)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "precision": 10, + "scale": 0, + "mappedType": "decimal" + }, + "token": { + "name": "token", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, + "method": { + "name": "method", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "enumItems": [ + "Online", + "Cash", + "Credit" + ], + "mappedType": "enum" + }, + "gateway": { + "name": "gateway", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "enumItems": [ + "zarinpal" + ], + "mappedType": "enum" + }, + "transaction_id": { + "name": "transaction_id", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, + "status": { + "name": "status", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "enumItems": [ + "pending", + "paid", + "failed", + "refunded" + ], + "mappedType": "enum" + }, + "verify_response": { + "name": "verify_response", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "paid_at": { + "name": "paid_at", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, + "failed_at": { + "name": "failed_at", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, + "attachments": { + "name": "attachments", + "type": "text[]", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "array" + }, + "description": { + "name": "description", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + } + }, + "name": "payments", + "schema": "public", + "indexes": [ + { + "columnNames": [ + "invoice_id" + ], + "composite": false, + "keyName": "payments_invoice_id_index", + "constraint": false, + "primary": false, + "unique": false + }, + { + "columnNames": [ + "token" + ], + "composite": false, + "keyName": "payments_token_unique", + "constraint": true, + "primary": false, + "unique": true + }, + { + "keyName": "payments_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "payments_invoice_id_foreign": { + "constraintName": "payments_invoice_id_foreign", + "columnNames": [ + "invoice_id" + ], + "localTableName": "public.payments", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.invoices", + "updateRule": "cascade" + }, + "payments_creator_id_foreign": { + "constraintName": "payments_creator_id_foreign", + "columnNames": [ + "creator_id" + ], + "localTableName": "public.payments", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.admins", + "deleteRule": "set null", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "invoice_id": { + "name": "invoice_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "product_id": { + "name": "product_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "quantity": { + "name": "quantity", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "unit_price": { + "name": "unit_price", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "sub_total": { + "name": "sub_total", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + }, + "discount": { + "name": "discount", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + }, + "total": { + "name": "total", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + }, + "description": { + "name": "description", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + } + }, + "name": "invoice_items", + "schema": "public", + "indexes": [ + { + "keyName": "invoice_items_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "invoice_items_invoice_id_foreign": { + "constraintName": "invoice_items_invoice_id_foreign", + "columnNames": [ + "invoice_id" + ], + "localTableName": "public.invoice_items", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.invoices", + "updateRule": "cascade" + }, + "invoice_items_product_id_foreign": { + "constraintName": "invoice_items_product_id_foreign", + "columnNames": [ + "product_id" + ], + "localTableName": "public.invoice_items", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.products", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "invoice_item_id": { + "name": "invoice_item_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "product_id": { + "name": "product_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "print_id": { + "name": "print_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "title": { + "name": "title", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, + "type_id": { + "name": "type_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "user_id": { + "name": "user_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "designer_id": { + "name": "designer_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "creator_id": { + "name": "creator_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 26, + "mappedType": "character" + }, + "order_number": { + "name": "order_number", + "type": "serial", + "unsigned": true, + "autoincrement": true, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "status": { + "name": "status", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "'created'", + "enumItems": [ + "created", + "invoiced", + "waiting_to_confirm_invoice", + "design_initiated", + "design_finished", + "design_revision", + "ready_to_printing", + "in_printing", + "ready_for_delivery", + "delivered", + "after_print_cover", + "after_print_boxing", + "after_print_cartoning", + "finished", + "canceled" + ], + "mappedType": "enum" + }, + "estimated_days": { + "name": "estimated_days", + "type": "int", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + }, + "attachments": { + "name": "attachments", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + } + }, + "name": "orders", + "schema": "public", + "indexes": [ + { + "columnNames": [ + "print_id" + ], + "composite": false, + "keyName": "orders_print_id_unique", + "constraint": true, + "primary": false, + "unique": true + }, + { + "keyName": "orders_user_id_index", + "columnNames": [ + "user_id" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, + { + "keyName": "orders_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "orders_invoice_item_id_foreign": { + "constraintName": "orders_invoice_item_id_foreign", + "columnNames": [ + "invoice_item_id" + ], + "localTableName": "public.orders", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.invoice_items", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "orders_product_id_foreign": { + "constraintName": "orders_product_id_foreign", + "columnNames": [ + "product_id" + ], + "localTableName": "public.orders", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.products", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "orders_print_id_foreign": { + "constraintName": "orders_print_id_foreign", + "columnNames": [ + "print_id" + ], + "localTableName": "public.orders", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.prints", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "orders_type_id_foreign": { + "constraintName": "orders_type_id_foreign", + "columnNames": [ + "type_id" + ], + "localTableName": "public.orders", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.categories", + "updateRule": "cascade" + }, + "orders_user_id_foreign": { + "constraintName": "orders_user_id_foreign", + "columnNames": [ + "user_id" + ], + "localTableName": "public.orders", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.users", + "updateRule": "cascade" + }, + "orders_designer_id_foreign": { + "constraintName": "orders_designer_id_foreign", + "columnNames": [ + "designer_id" + ], + "localTableName": "public.orders", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.admins", + "deleteRule": "set null", + "updateRule": "cascade" + }, + "orders_creator_id_foreign": { + "constraintName": "orders_creator_id_foreign", + "columnNames": [ + "creator_id" + ], + "localTableName": "public.orders", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.admins", + "deleteRule": "set null", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "title": { + "name": "title", + "type": "varchar(150)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 150, + "mappedType": "string" + }, + "content": { + "name": "content", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "user_id": { + "name": "user_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "is_read": { + "name": "is_read", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + } + }, + "name": "criticisms", + "schema": "public", + "indexes": [ + { + "keyName": "criticisms_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "criticisms_user_id_foreign": { + "constraintName": "criticisms_user_id_foreign", + "columnNames": [ + "user_id" + ], + "localTableName": "public.criticisms", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.users", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "file_url": { + "name": "file_url", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "criticism_id": { + "name": "criticism_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + } + }, + "name": "criticism_files", + "schema": "public", + "indexes": [ + { + "keyName": "criticism_files_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "criticism_files_criticism_id_foreign": { + "constraintName": "criticism_files_criticism_id_foreign", + "columnNames": [ + "criticism_id" + ], + "localTableName": "public.criticism_files", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.criticisms", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "user_id": { + "name": "user_id", + "type": "char(26)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 26, + "mappedType": "character" + }, + "invoice_id": { + "name": "invoice_id", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 255, + "mappedType": "string" + }, + "amount": { + "name": "amount", + "type": "numeric(10,0)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "precision": 10, + "scale": 0, + "mappedType": "decimal" + }, + "balance": { + "name": "balance", + "type": "numeric(10,0)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "precision": 10, + "scale": 0, + "mappedType": "decimal" + }, + "type": { + "name": "type", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "enumItems": [], + "mappedType": "enum" + } + }, + "name": "credit_transactions", + "schema": "public", + "indexes": [ + { + "keyName": "credit_transactions_user_id_index", + "columnNames": [ + "user_id" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, + { + "keyName": "credit_transactions_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "constraint": true, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "credit_transactions_user_id_foreign": { + "constraintName": "credit_transactions_user_id_foreign", + "columnNames": [ + "user_id" + ], + "localTableName": "public.credit_transactions", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.users", + "updateRule": "cascade" + } + }, + "nativeEnums": {} + } + ], + "nativeEnums": {} +} diff --git a/src/app.module.ts b/src/app.module.ts index a226e98..109f55b 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -21,6 +21,7 @@ import { RequestModule } from './modules/request/request.module'; import { InvoiceModule } from './modules/invoice/invoice.module'; import { OrderModule } from './modules/order/order.module'; import { LearningModule } from './modules/learnings/learning.module'; +import { CriticismModule } from './modules/criticisms/criticisms.module'; @Module({ imports: [ @@ -50,6 +51,7 @@ import { LearningModule } from './modules/learnings/learning.module'; InvoiceModule, OrderModule, LearningModule, + CriticismModule, ], controllers: [], providers: [], diff --git a/src/common/enums/message.enum.ts b/src/common/enums/message.enum.ts index 7e80634..5c41d17 100755 --- a/src/common/enums/message.enum.ts +++ b/src/common/enums/message.enum.ts @@ -137,6 +137,17 @@ export const enum LearningMessage { VIDEO_DURATION_INVALID = 'مدت زمان ویدیو نامعتبر است', } +export const enum CriticismMessage { + NOT_FOUND = 'انتقاد مورد نظر یافت نشد', + TITLE_IS_REQUIRED = 'عنوان الزامی است', + TITLE_STRING = 'عنوان باید رشته باشد', + CONTENT_IS_REQUIRED = 'محتوا الزامی است', + CONTENT_IS_STRING = 'محتوا باید رشته باشد', + FILES_IS_REQUIRED = 'فایل‌ها الزامی است', + FILES_SHOULD_BE_URL = 'آدرس فایل باید URL معتبر باشد', + SEARCH_QUERY_STRING = 'رشته جستجو باید یک رشته باشد', +} + export const enum productMessage { NOT_FOUND = 'کالایی با این مشخصات یافت نشد', } diff --git a/src/common/enums/permission.enum.ts b/src/common/enums/permission.enum.ts index 3c9ba0c..718b8be 100644 --- a/src/common/enums/permission.enum.ts +++ b/src/common/enums/permission.enum.ts @@ -43,6 +43,8 @@ export enum PermissionEnum { MANAGE_PRINT = 'view_print', MANAGE_LEARNINGS = 'manage_learnings', + + MANAGE_CRITICISMS = 'manage_criticisms', } /** @@ -77,5 +79,6 @@ export const PermissionTitles: Record = { [PermissionEnum.DELETE_ORDER]: "", [PermissionEnum.CREATE_PRINT]: "ایجاد فرم چاپ برای سفارش", [PermissionEnum.MANAGE_PRINT]: "مدیریت فرم چاپ", - [PermissionEnum.MANAGE_LEARNINGS]: "مدیریت آموزش‌ها" + [PermissionEnum.MANAGE_LEARNINGS]: "مدیریت آموزش‌ها", + [PermissionEnum.MANAGE_CRITICISMS]: "مدیریت انتقادها و پیشنهادها" }; diff --git a/src/modules/criticisms/DTO/create-criticism.dto.ts b/src/modules/criticisms/DTO/create-criticism.dto.ts new file mode 100755 index 0000000..227aa07 --- /dev/null +++ b/src/modules/criticisms/DTO/create-criticism.dto.ts @@ -0,0 +1,24 @@ +import { ApiProperty } from "@nestjs/swagger"; +import { IsNotEmpty, IsOptional, IsString, IsUrl } from "class-validator"; + +import { CriticismMessage } from "../../../common/enums/message.enum"; + +export class CreateCriticismDto { + @IsNotEmpty({ message: CriticismMessage.TITLE_IS_REQUIRED }) + @IsString({ message: CriticismMessage.TITLE_STRING }) + @ApiProperty({ type: String, description: "title of criticism", example: "انتقاد بابت مشکلات" }) + title: string; + + @IsNotEmpty({ message: CriticismMessage.CONTENT_IS_REQUIRED }) + @IsString({ message: CriticismMessage.CONTENT_IS_STRING }) + @ApiProperty({ type: String, description: "description of criticism", example: "متن انتقاد" }) + content: string; + + @IsOptional() + @IsUrl({ protocols: ['http', 'https'], require_protocol: true }, { message: CriticismMessage.FILES_SHOULD_BE_URL, each: true }) + @ApiProperty({ + description: "The ulr of the criticism files", + example: ["https://example.com/image1.png", "https://example.com/image2.png"], + }) + files: string[]; +} diff --git a/src/modules/criticisms/DTO/search-criticism-query.dto.ts b/src/modules/criticisms/DTO/search-criticism-query.dto.ts new file mode 100755 index 0000000..10abcd1 --- /dev/null +++ b/src/modules/criticisms/DTO/search-criticism-query.dto.ts @@ -0,0 +1,17 @@ +import { ApiPropertyOptional } from "@nestjs/swagger"; +import { IsDateString, IsOptional, IsString } from "class-validator"; + +import { PaginationDto } from "../../../common/DTO/pagination.dto"; +import { CriticismMessage } from "../../../common/enums/message.enum"; + +export class SearchCriticismQueryDto extends PaginationDto { + @IsOptional() + @IsDateString() + @ApiPropertyOptional({ description: "since query", example: "2025-01-27" }) + since?: string; + + @IsOptional() + @IsString({ message: CriticismMessage.SEARCH_QUERY_STRING }) + @ApiPropertyOptional({ description: "Search query", example: "search query" }) + q?: string; +} diff --git a/src/modules/criticisms/criticisms.controller.ts b/src/modules/criticisms/criticisms.controller.ts new file mode 100755 index 0000000..e842de0 --- /dev/null +++ b/src/modules/criticisms/criticisms.controller.ts @@ -0,0 +1,49 @@ +import { Body, Controller, Delete, Get, Param, Post, Query, UseGuards } from '@nestjs/common'; +import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger'; + +import { CreateCriticismDto } from './DTO/create-criticism.dto'; +import { SearchCriticismQueryDto } from './DTO/search-criticism-query.dto'; +import { CriticismsService } from './providers/criticisms.service'; +import { AuthGuard } from '../auth/guards/auth.guard'; +import { AdminAuthGuard } from '../auth/guards/adminAuth.guard'; +import { Permissions } from '../../common/decorators/permissions.decorator'; +import { UserId } from '../../common/decorators'; +import { PermissionEnum } from '../../common/enums/permission.enum'; + +@ApiTags('Criticism') +@ApiBearerAuth() +@Controller('criticisms') +export class CriticismController { + constructor(private readonly criticismService: CriticismsService) {} + + @Post() + @UseGuards(AuthGuard) + @ApiOperation({ summary: 'Create a new criticism' }) + create(@Body() createDto: CreateCriticismDto, @UserId() userId: string) { + return this.criticismService.create(createDto, userId); + } + + @Get() + @UseGuards(AdminAuthGuard) + @Permissions(PermissionEnum.MANAGE_CRITICISMS) + @ApiOperation({ summary: 'Get all criticisms (admin only)' }) + findAll(@Query() queryDto: SearchCriticismQueryDto) { + return this.criticismService.findAll(queryDto); + } + + @Get(':id') + @UseGuards(AdminAuthGuard) + @Permissions(PermissionEnum.MANAGE_CRITICISMS) + @ApiOperation({ summary: 'Get one criticism by id (admin only)' }) + findOne(@Param('id') id: string) { + return this.criticismService.findOneAndMarkAsRead(id); + } + + @Delete(':id') + @UseGuards(AdminAuthGuard) + @Permissions(PermissionEnum.MANAGE_CRITICISMS) + @ApiOperation({ summary: 'Delete one criticism by id (admin only)' }) + delete(@Param('id') id: string) { + return this.criticismService.delete(id); + } +} diff --git a/src/modules/criticisms/criticisms.module.ts b/src/modules/criticisms/criticisms.module.ts new file mode 100755 index 0000000..5e79d40 --- /dev/null +++ b/src/modules/criticisms/criticisms.module.ts @@ -0,0 +1,27 @@ +import { Module } from '@nestjs/common'; +import { MikroOrmModule } from '@mikro-orm/nestjs'; + +import { CriticismController } from './criticisms.controller'; +import { CriticismFile } from './entities/criticism-file.entity'; +import { Criticism } from './entities/criticism.entity'; +import { CriticismsService } from './providers/criticisms.service'; +import { CriticismFileRepository } from './repositories/criticisms-file.repository'; +import { CriticismRepository } from './repositories/criticisms.repository'; +import { UserModule } from '../user/user.module'; +import { NotificationsModule } from '../notification/notifications.module'; +import { AdminModule } from '../admin/admin.module'; +import { JwtModule } from '@nestjs/jwt'; + +@Module({ + imports: [ + MikroOrmModule.forFeature([Criticism, CriticismFile]), + UserModule, + NotificationsModule, + AdminModule, + JwtModule + ], + providers: [CriticismsService, CriticismRepository, CriticismFileRepository], + controllers: [CriticismController], + exports: [CriticismsService], +}) +export class CriticismModule {} diff --git a/src/modules/criticisms/entities/criticism-file.entity.ts b/src/modules/criticisms/entities/criticism-file.entity.ts new file mode 100755 index 0000000..ea1a6c0 --- /dev/null +++ b/src/modules/criticisms/entities/criticism-file.entity.ts @@ -0,0 +1,14 @@ +import { Entity, ManyToOne, OptionalProps, Property } from '@mikro-orm/core'; +import { BaseEntity } from '../../../common/entities/base.entity'; +import { Criticism } from './criticism.entity'; + +@Entity({ tableName: 'criticism_files' }) +export class CriticismFile extends BaseEntity { + [OptionalProps]?: 'createdAt' | 'deletedAt'; + + @Property({ type: 'varchar', length: 255 }) + fileUrl: string; + + @ManyToOne(() => Criticism) + criticism: Criticism; +} diff --git a/src/modules/criticisms/entities/criticism.entity.ts b/src/modules/criticisms/entities/criticism.entity.ts new file mode 100755 index 0000000..510b953 --- /dev/null +++ b/src/modules/criticisms/entities/criticism.entity.ts @@ -0,0 +1,24 @@ +import { Cascade, Collection, Entity, ManyToOne, OneToMany, OptionalProps, Property } from '@mikro-orm/core'; +import { BaseEntity } from '../../../common/entities/base.entity'; +import { User } from '../../user/entities/user.entity'; +import { CriticismFile } from './criticism-file.entity'; + +@Entity({ tableName: 'criticisms' }) +export class Criticism extends BaseEntity { + [OptionalProps]?: 'createdAt' | 'deletedAt'; + + @Property({ type: 'varchar', length: 150 }) + title: string; + + @Property({ type: 'text' }) + content: string; + + @ManyToOne(() => User) + user: User; + + @Property({ default: false }) + isRead: boolean = false; + + @OneToMany(() => CriticismFile, (criticismFile) => criticismFile.criticism, { cascade: [Cascade.ALL] }) + files = new Collection(this); +} diff --git a/src/modules/criticisms/providers/criticisms.service.ts b/src/modules/criticisms/providers/criticisms.service.ts new file mode 100755 index 0000000..47425f0 --- /dev/null +++ b/src/modules/criticisms/providers/criticisms.service.ts @@ -0,0 +1,135 @@ +import { BadRequestException, Injectable } from '@nestjs/common'; +import { EntityManager } from '@mikro-orm/postgresql'; +import { CommonMessage, CriticismMessage } from '../../../common/enums/message.enum'; +import { NotificationQueueService } from '../../notification/services/notification-queue.service'; +import { AdminRepository } from '../../admin/repositories/admin.repository'; +import { PermissionEnum } from '../../../common/enums/permission.enum'; +import { NotifEvent } from '../../notification/interfaces/notification.interface'; +import { Notification } from '../../notification/entities/notification.entity'; +import { CreateCriticismDto } from '../DTO/create-criticism.dto'; +import { SearchCriticismQueryDto } from '../DTO/search-criticism-query.dto'; +import { Criticism } from '../entities/criticism.entity'; +import { CriticismFile } from '../entities/criticism-file.entity'; +import { CriticismRepository } from '../repositories/criticisms.repository'; +import { UserService } from '../../user/providers/user.service'; + +@Injectable() +export class CriticismsService { + constructor( + private readonly criticismRepository: CriticismRepository, + private readonly userService: UserService, + private readonly em: EntityManager, + private readonly adminRepository: AdminRepository, + private readonly notificationQueueService: NotificationQueueService, + ) {} + + async create(createDto: CreateCriticismDto, userId: string) { + return this.em.transactional(async (em) => { + const user = await this.userService.findOrFail(userId); + + const criticism = em.create(Criticism, { + title: createDto.title, + content: createDto.content, + user, + isRead: false, + }); + + for (const fileUrl of createDto.files ?? []) { + const file = em.create(CriticismFile, { fileUrl, criticism }); + criticism.files.add(file); + } + + await em.persistAndFlush(criticism); + + await this.notifyAdminsWithPermission(criticism, em); + + return { + message: CommonMessage.CREATED, + criticism, + }; + }); + } + + async findAll(queryDto: SearchCriticismQueryDto) { + const page = queryDto.page ?? 1; + const limit = queryDto.limit ?? 10; + const offset = (page - 1) * limit; + + const where: Record = {}; + + if (queryDto.since) { + where.createdAt = { $gte: new Date(queryDto.since) }; + } + + if (queryDto.q) { + where.title = { $like: `%${queryDto.q}%` }; + } + + const [criticisms, count] = await this.em.findAndCount(Criticism, where, { + orderBy: { createdAt: 'DESC' }, + offset, + limit, + populate: ['user', 'files'], + }); + + return { + criticisms, + count, + paginate: true, + }; + } + + async findOneAndMarkAsRead(id: string) { + const criticism = await this.criticismRepository.findOne( + { id }, + { populate: ['user', 'files'] }, + ); + if (!criticism) throw new BadRequestException(CriticismMessage.NOT_FOUND); + criticism.isRead = true; + await this.em.flush(); + return { + criticism, + }; + } + + async delete(id: string) { + const criticism = await this.criticismRepository.findOne({ id }); + if (!criticism) throw new BadRequestException(CriticismMessage.NOT_FOUND); + + await this.em.removeAndFlush(criticism); + return { + message: CommonMessage.DELETED, + }; + } + + private async notifyAdminsWithPermission(criticism: Criticism, em: EntityManager) { + const admins = await this.adminRepository.findAdminsWithPermission( + PermissionEnum.MANAGE_CRITICISMS, + ); + + if (admins.length === 0) return; + + const user = criticism.user; + const fullName = `${user.firstName ?? ''} ${user.lastName ?? ''}`.trim() || 'کاربر'; + const body = `انتقاد جدید از ${fullName}: ${criticism.title}`; + + const notifications = admins.map((admin) => + em.create(Notification, { + admin, + title: NotifEvent.NEW_CRITICISM, + content: body, + }), + ); + + await em.persistAndFlush(notifications); + + await this.notificationQueueService.addBulkInAppNotifications( + notifications.map((n) => ({ + recipient: { adminId: n.admin!.id }, + subject: NotifEvent.NEW_CRITICISM, + body, + notificationId: n.id, + })), + ); + } +} diff --git a/src/modules/criticisms/repositories/criticisms-file.repository.ts b/src/modules/criticisms/repositories/criticisms-file.repository.ts new file mode 100755 index 0000000..ba2c8d2 --- /dev/null +++ b/src/modules/criticisms/repositories/criticisms-file.repository.ts @@ -0,0 +1,10 @@ +import { Injectable } from '@nestjs/common'; +import { EntityManager, EntityRepository } from '@mikro-orm/postgresql'; +import { CriticismFile } from '../entities/criticism-file.entity'; + +@Injectable() +export class CriticismFileRepository extends EntityRepository { + constructor(readonly em: EntityManager) { + super(em, CriticismFile); + } +} diff --git a/src/modules/criticisms/repositories/criticisms.repository.ts b/src/modules/criticisms/repositories/criticisms.repository.ts new file mode 100755 index 0000000..2b66645 --- /dev/null +++ b/src/modules/criticisms/repositories/criticisms.repository.ts @@ -0,0 +1,10 @@ +import { Injectable } from '@nestjs/common'; +import { EntityManager, EntityRepository } from '@mikro-orm/postgresql'; +import { Criticism } from '../entities/criticism.entity'; + +@Injectable() +export class CriticismRepository extends EntityRepository { + constructor(readonly em: EntityManager) { + super(em, Criticism); + } +} diff --git a/src/modules/notification/interfaces/notification.interface.ts b/src/modules/notification/interfaces/notification.interface.ts index cee31c2..6143ba2 100644 --- a/src/modules/notification/interfaces/notification.interface.ts +++ b/src/modules/notification/interfaces/notification.interface.ts @@ -14,6 +14,7 @@ export enum NotifEvent { NEW_ORDER = 'newOrder', // for chapkhane sms bere DESIGNER_ASSIGN = 'designerAssign', PAYMENT_SUCCESS = 'paymentSuccess', + NEW_CRITICISM = 'newCriticism', } export type recipientType = { userId: string } | { adminId: string }; diff --git a/src/modules/order/order.module.ts b/src/modules/order/order.module.ts index cc47e37..0a4ae89 100644 --- a/src/modules/order/order.module.ts +++ b/src/modules/order/order.module.ts @@ -16,6 +16,7 @@ import { UserModule } from '../user/user.module'; import { UtilsModule } from '../util/utils.module'; import { ProductModule } from '../product/product.module'; import { TicketModule } from '../ticket/ticket.module'; +import { OrderPrintRepository } from './repositories/order-print.repository'; @Module({ imports: [ @@ -32,7 +33,7 @@ import { TicketModule } from '../ticket/ticket.module'; ], controllers: [OrderController], providers: [OrderService, OrderRepository, OrderListeners, - OrdersCrone,], + OrdersCrone, OrderPrintRepository], exports: [OrderRepository, OrderService], }) export class OrderModule { } diff --git a/src/modules/user/entities/user.entity.ts b/src/modules/user/entities/user.entity.ts index 4f46343..57faadc 100644 --- a/src/modules/user/entities/user.entity.ts +++ b/src/modules/user/entities/user.entity.ts @@ -1,6 +1,7 @@ -import { Entity, Index, Property, OneToMany, Collection, Cascade, PrimaryKey, OptionalProps } from '@mikro-orm/core'; +import { Entity, Index, Property, OneToMany, Collection, PrimaryKey, OptionalProps } from '@mikro-orm/core'; import { BaseEntity } from '../../../common/entities/base.entity'; import { LearningProgress } from '../../learnings/entities/learning-progress.entity'; +import { Criticism } from '../../criticisms/entities/criticism.entity'; // import { Order } from 'src/modules/order/entities/order.entity'; import { normalizePhone } from '../../util/phone.util'; import { ulid } from 'ulid'; @@ -12,6 +13,9 @@ export class User extends BaseEntity { @OneToMany(() => LearningProgress, (lp) => lp.user) learningProgress = new Collection(this); + @OneToMany(() => Criticism, (c) => c.user) + criticisms = new Collection(this); + // @OneToMany(() => Order, order => order.user) // orders = new Collection(this);