diff --git a/src/db/migrations/0002_melodic_baron_strucker.sql b/src/db/migrations/0002_melodic_baron_strucker.sql new file mode 100644 index 0000000000000000000000000000000000000000..cca2115757e93bd993f7b6cd7f4ce86f4792e1a7 --- /dev/null +++ b/src/db/migrations/0002_melodic_baron_strucker.sql @@ -0,0 +1,4 @@ +ALTER TABLE "resources" RENAME COLUMN "resource_state" TO "state";--> statement-breakpoint +ALTER TABLE "complaints" ADD COLUMN "q5" boolean;--> statement-breakpoint +ALTER TABLE "complaints" ADD COLUMN "q6" boolean;--> statement-breakpoint +ALTER TABLE "complaints" ADD COLUMN "q7" boolean; \ No newline at end of file diff --git a/src/db/migrations/meta/0002_snapshot.json b/src/db/migrations/meta/0002_snapshot.json new file mode 100644 index 0000000000000000000000000000000000000000..83f28ef8446526d9f709abd3dbc52ecbc3b9f787 --- /dev/null +++ b/src/db/migrations/meta/0002_snapshot.json @@ -0,0 +1,2660 @@ +{ + "id": "32236e16-db0c-4a27-b1a6-ec3db237e479", + "prevId": "fa865788-c6ff-4a5a-8b90-acc4275c1526", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.achievements": { + "name": "achievements", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reward_experience": { + "name": "reward_experience", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "reward_points": { + "name": "reward_points", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "review_state": { + "name": "review_state", + "type": "review_state", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'under_review'" + }, + "repeatable": { + "name": "repeatable", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "is_resettable": { + "name": "is_resettable", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "achievements_id_unique": { + "name": "achievements_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.actions": { + "name": "actions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "actions_id_unique": { + "name": "actions_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.collection_likes": { + "name": "collection_likes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "collection_id": { + "name": "collection_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "collection_likes_user_id_users_id_fk": { + "name": "collection_likes_user_id_users_id_fk", + "tableFrom": "collection_likes", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "collection_likes_collection_id_collections_id_fk": { + "name": "collection_likes_collection_id_collections_id_fk", + "tableFrom": "collection_likes", + "tableTo": "collections", + "columnsFrom": [ + "collection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "collection_likes_id_unique": { + "name": "collection_likes_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.collection_resources": { + "name": "collection_resources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "collection_id": { + "name": "collection_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "collection_resources_collection_id_collections_id_fk": { + "name": "collection_resources_collection_id_collections_id_fk", + "tableFrom": "collection_resources", + "tableTo": "collections", + "columnsFrom": [ + "collection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "collection_resources_resource_id_resources_id_fk": { + "name": "collection_resources_resource_id_resources_id_fk", + "tableFrom": "collection_resources", + "tableTo": "resources", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "collection_resources_id_unique": { + "name": "collection_resources_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.collection_stats": { + "name": "collection_stats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "views": { + "name": "views", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "downloads": { + "name": "downloads", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "likes": { + "name": "likes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "shares": { + "name": "shares", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "score": { + "name": "score", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0.0'" + }, + "follows": { + "name": "follows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "collection_stats_id_unique": { + "name": "collection_stats_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.collections": { + "name": "collections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_private": { + "name": "is_private", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "thumbnail": { + "name": "thumbnail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "collection_stats_id": { + "name": "collection_stats_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "collections_user_id_users_id_fk": { + "name": "collections_user_id_users_id_fk", + "tableFrom": "collections", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "collections_collection_stats_id_collection_stats_id_fk": { + "name": "collections_collection_stats_id_collection_stats_id_fk", + "tableFrom": "collections", + "tableTo": "collection_stats", + "columnsFrom": [ + "collection_stats_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "collections_id_unique": { + "name": "collections_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "collections_collection_stats_id_unique": { + "name": "collections_collection_stats_id_unique", + "nullsNotDistinct": false, + "columns": [ + "collection_stats_id" + ] + } + } + }, + "public.commentReply": { + "name": "commentReply", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "comment_id": { + "name": "comment_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "update_at": { + "name": "update_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "commentReply_user_id_users_id_fk": { + "name": "commentReply_user_id_users_id_fk", + "tableFrom": "commentReply", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "commentReply_comment_id_comments_id_fk": { + "name": "commentReply_comment_id_comments_id_fk", + "tableFrom": "commentReply", + "tableTo": "comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "commentReply_id_unique": { + "name": "commentReply_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.comments": { + "name": "comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "comments_user_id_users_id_fk": { + "name": "comments_user_id_users_id_fk", + "tableFrom": "comments", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "comments_resource_id_resources_id_fk": { + "name": "comments_resource_id_resources_id_fk", + "tableFrom": "comments", + "tableTo": "resources", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "comments_id_unique": { + "name": "comments_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.complaints": { + "name": "complaints", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "state": { + "name": "state", + "type": "complaints_state", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'complained'" + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "denouncer_id": { + "name": "denouncer_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "collection_id": { + "name": "collection_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evaluated_at": { + "name": "evaluated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "q1": { + "name": "q1", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q2": { + "name": "q2", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q3": { + "name": "q3", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q4": { + "name": "q4", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q5": { + "name": "q5", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q6": { + "name": "q6", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q7": { + "name": "q7", + "type": "boolean", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "complaints_denouncer_id_users_id_fk": { + "name": "complaints_denouncer_id_users_id_fk", + "tableFrom": "complaints", + "tableTo": "users", + "columnsFrom": [ + "denouncer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "complaints_resource_id_resources_id_fk": { + "name": "complaints_resource_id_resources_id_fk", + "tableFrom": "complaints", + "tableTo": "resources", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "complaints_collection_id_collections_id_fk": { + "name": "complaints_collection_id_collections_id_fk", + "tableFrom": "complaints", + "tableTo": "collections", + "columnsFrom": [ + "collection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "complaints_user_id_users_id_fk": { + "name": "complaints_user_id_users_id_fk", + "tableFrom": "complaints", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "complaints_id_unique": { + "name": "complaints_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.educational_stages": { + "name": "educational_stages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "educational_stages_id_unique": { + "name": "educational_stages_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.followers": { + "name": "followers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "follower_id": { + "name": "follower_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "followers_user_id_users_id_fk": { + "name": "followers_user_id_users_id_fk", + "tableFrom": "followers", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "followers_follower_id_users_id_fk": { + "name": "followers_follower_id_users_id_fk", + "tableFrom": "followers", + "tableTo": "users", + "columnsFrom": [ + "follower_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "followers_id_unique": { + "name": "followers_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.institutions": { + "name": "institutions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "uf": { + "name": "uf", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "city": { + "name": "city", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "cep": { + "name": "cep", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "institutions_id_unique": { + "name": "institutions_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.item_achievements": { + "name": "item_achievements", + "schema": "", + "columns": { + "item_id": { + "name": "item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "achievement_id": { + "name": "achievement_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "item_achievements_item_id_items_id_fk": { + "name": "item_achievements_item_id_items_id_fk", + "tableFrom": "item_achievements", + "tableTo": "items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "item_achievements_achievement_id_achievements_id_fk": { + "name": "item_achievements_achievement_id_achievements_id_fk", + "tableFrom": "item_achievements", + "tableTo": "achievements", + "columnsFrom": [ + "achievement_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "item_achievements_item_id_achievement_id_pk": { + "name": "item_achievements_item_id_achievement_id_pk", + "columns": [ + "item_id", + "achievement_id" + ] + } + }, + "uniqueConstraints": {} + }, + "public.items": { + "name": "items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "price": { + "name": "price", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "items_id_unique": { + "name": "items_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.languages": { + "name": "languages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "languages_id_unique": { + "name": "languages_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "languages_code_unique": { + "name": "languages_code_unique", + "nullsNotDistinct": false, + "columns": [ + "code" + ] + } + } + }, + "public.licenses": { + "name": "licenses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "licenses_id_unique": { + "name": "licenses_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.notifications": { + "name": "notifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "action_id": { + "name": "action_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_user_id": { + "name": "target_user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_resource_id": { + "name": "target_resource_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "target_collection_id": { + "name": "target_collection_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "notifications_action_id_actions_id_fk": { + "name": "notifications_action_id_actions_id_fk", + "tableFrom": "notifications", + "tableTo": "actions", + "columnsFrom": [ + "action_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notifications_actor_user_id_users_id_fk": { + "name": "notifications_actor_user_id_users_id_fk", + "tableFrom": "notifications", + "tableTo": "users", + "columnsFrom": [ + "actor_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notifications_target_user_id_users_id_fk": { + "name": "notifications_target_user_id_users_id_fk", + "tableFrom": "notifications", + "tableTo": "users", + "columnsFrom": [ + "target_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notifications_target_resource_id_resources_id_fk": { + "name": "notifications_target_resource_id_resources_id_fk", + "tableFrom": "notifications", + "tableTo": "resources", + "columnsFrom": [ + "target_resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notifications_target_collection_id_collections_id_fk": { + "name": "notifications_target_collection_id_collections_id_fk", + "tableFrom": "notifications", + "tableTo": "collections", + "columnsFrom": [ + "target_collection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "notifications_id_unique": { + "name": "notifications_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.object_types": { + "name": "object_types", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "object_types_id_unique": { + "name": "object_types_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.resource_educational_stages": { + "name": "resource_educational_stages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "educational_stage_id": { + "name": "educational_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "resource_educational_stages_resource_id_resources_id_fk": { + "name": "resource_educational_stages_resource_id_resources_id_fk", + "tableFrom": "resource_educational_stages", + "tableTo": "resources", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resource_educational_stages_educational_stage_id_educational_stages_id_fk": { + "name": "resource_educational_stages_educational_stage_id_educational_stages_id_fk", + "tableFrom": "resource_educational_stages", + "tableTo": "educational_stages", + "columnsFrom": [ + "educational_stage_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "resource_educational_stages_id_unique": { + "name": "resource_educational_stages_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.resource_languages": { + "name": "resource_languages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "language_id": { + "name": "language_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "resource_languages_resource_id_resources_id_fk": { + "name": "resource_languages_resource_id_resources_id_fk", + "tableFrom": "resource_languages", + "tableTo": "resources", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resource_languages_language_id_languages_id_fk": { + "name": "resource_languages_language_id_languages_id_fk", + "tableFrom": "resource_languages", + "tableTo": "languages", + "columnsFrom": [ + "language_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "resource_languages_id_unique": { + "name": "resource_languages_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.resource_likes": { + "name": "resource_likes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "resource_likes_user_id_users_id_fk": { + "name": "resource_likes_user_id_users_id_fk", + "tableFrom": "resource_likes", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resource_likes_resource_id_resources_id_fk": { + "name": "resource_likes_resource_id_resources_id_fk", + "tableFrom": "resource_likes", + "tableTo": "resources", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "resource_likes_id_unique": { + "name": "resource_likes_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.resource_stats": { + "name": "resource_stats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "views": { + "name": "views", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "downloads": { + "name": "downloads", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "likes": { + "name": "likes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "shares": { + "name": "shares", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "score": { + "name": "score", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0.0'" + }, + "follows": { + "name": "follows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "comments": { + "name": "comments", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "resource_stats_id_unique": { + "name": "resource_stats_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.resource_subjects": { + "name": "resource_subjects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "subject_id": { + "name": "subject_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "resource_subjects_resource_id_resources_id_fk": { + "name": "resource_subjects_resource_id_resources_id_fk", + "tableFrom": "resource_subjects", + "tableTo": "resources", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resource_subjects_subject_id_subjects_id_fk": { + "name": "resource_subjects_subject_id_subjects_id_fk", + "tableFrom": "resource_subjects", + "tableTo": "subjects", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "resource_subjects_id_unique": { + "name": "resource_subjects_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.resources": { + "name": "resources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "state": { + "name": "state", + "type": "resource_state", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "author": { + "name": "author", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "link": { + "name": "link", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "thumbnail": { + "name": "thumbnail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "published_at": { + "name": "published_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "resource_stats_id": { + "name": "resource_stats_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "object_type_id": { + "name": "object_type_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "license_id": { + "name": "license_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "resources_user_id_users_id_fk": { + "name": "resources_user_id_users_id_fk", + "tableFrom": "resources", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resources_resource_stats_id_resource_stats_id_fk": { + "name": "resources_resource_stats_id_resource_stats_id_fk", + "tableFrom": "resources", + "tableTo": "resource_stats", + "columnsFrom": [ + "resource_stats_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resources_object_type_id_object_types_id_fk": { + "name": "resources_object_type_id_object_types_id_fk", + "tableFrom": "resources", + "tableTo": "object_types", + "columnsFrom": [ + "object_type_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resources_license_id_licenses_id_fk": { + "name": "resources_license_id_licenses_id_fk", + "tableFrom": "resources", + "tableTo": "licenses", + "columnsFrom": [ + "license_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "resources_id_unique": { + "name": "resources_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "resources_resource_stats_id_unique": { + "name": "resources_resource_stats_id_unique", + "nullsNotDistinct": false, + "columns": [ + "resource_stats_id" + ] + } + } + }, + "public.roles": { + "name": "roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "roles_id_unique": { + "name": "roles_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "roles_name_unique": { + "name": "roles_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + } + }, + "public.subjects": { + "name": "subjects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "subjects_id_unique": { + "name": "subjects_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.submissions": { + "name": "submissions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "is_accepted": { + "name": "is_accepted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "justification": { + "name": "justification", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "submitter_id": { + "name": "submitter_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "curator_id": { + "name": "curator_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "answered_at": { + "name": "answered_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "q1": { + "name": "q1", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q2": { + "name": "q2", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q3": { + "name": "q3", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q4": { + "name": "q4", + "type": "boolean", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "submissions_resource_id_resources_id_fk": { + "name": "submissions_resource_id_resources_id_fk", + "tableFrom": "submissions", + "tableTo": "resources", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "submissions_submitter_id_users_id_fk": { + "name": "submissions_submitter_id_users_id_fk", + "tableFrom": "submissions", + "tableTo": "users", + "columnsFrom": [ + "submitter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "submissions_curator_id_users_id_fk": { + "name": "submissions_curator_id_users_id_fk", + "tableFrom": "submissions", + "tableTo": "users", + "columnsFrom": [ + "curator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "submissions_id_unique": { + "name": "submissions_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.user_achievements": { + "name": "user_achievements", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "achievement_id": { + "name": "achievement_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_achievements_user_id_users_id_fk": { + "name": "user_achievements_user_id_users_id_fk", + "tableFrom": "user_achievements", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_achievements_achievement_id_users_id_fk": { + "name": "user_achievements_achievement_id_users_id_fk", + "tableFrom": "user_achievements", + "tableTo": "users", + "columnsFrom": [ + "achievement_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_achievements_id_unique": { + "name": "user_achievements_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.user_collections": { + "name": "user_collections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "collection_id": { + "name": "collection_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_collections_user_id_users_id_fk": { + "name": "user_collections_user_id_users_id_fk", + "tableFrom": "user_collections", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_collections_collection_id_collections_id_fk": { + "name": "user_collections_collection_id_collections_id_fk", + "tableFrom": "user_collections", + "tableTo": "collections", + "columnsFrom": [ + "collection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_collections_id_unique": { + "name": "user_collections_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.user_institutions": { + "name": "user_institutions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "institution_id": { + "name": "institution_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_institutions_user_id_users_id_fk": { + "name": "user_institutions_user_id_users_id_fk", + "tableFrom": "user_institutions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_institutions_institution_id_institutions_id_fk": { + "name": "user_institutions_institution_id_institutions_id_fk", + "tableFrom": "user_institutions", + "tableTo": "institutions", + "columnsFrom": [ + "institution_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_institutions_id_unique": { + "name": "user_institutions_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.user_items": { + "name": "user_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_items_user_id_users_id_fk": { + "name": "user_items_user_id_users_id_fk", + "tableFrom": "user_items", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_items_item_id_items_id_fk": { + "name": "user_items_item_id_items_id_fk", + "tableFrom": "user_items", + "tableTo": "items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_items_id_unique": { + "name": "user_items_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.user_roles": { + "name": "user_roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_roles_user_id_users_id_fk": { + "name": "user_roles_user_id_users_id_fk", + "tableFrom": "user_roles", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_roles_role_id_roles_id_fk": { + "name": "user_roles_role_id_roles_id_fk", + "tableFrom": "user_roles", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_roles_id_unique": { + "name": "user_roles_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.user_stats": { + "name": "user_stats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "score": { + "name": "score", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0.0'" + }, + "likes": { + "name": "likes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "likes_received": { + "name": "likes_received", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "follows": { + "name": "follows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "followers": { + "name": "followers", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "collections": { + "name": "collections", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "submitted_resources": { + "name": "submitted_resources", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "approved_resources": { + "name": "approved_resources", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "reviewed_resources": { + "name": "reviewed_resources", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "comments": { + "name": "comments", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_stats_id_unique": { + "name": "user_stats_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'sem descrição'" + }, + "birthday": { + "name": "birthday", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "cpf": { + "name": "cpf", + "type": "varchar(11)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "confirmation_sent_at": { + "name": "confirmation_sent_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "reactivated_at": { + "name": "reactivated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "user_stats_id": { + "name": "user_stats_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "users_user_stats_id_user_stats_id_fk": { + "name": "users_user_stats_id_user_stats_id_fk", + "tableFrom": "users", + "tableTo": "user_stats", + "columnsFrom": [ + "user_stats_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_id_unique": { + "name": "users_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "users_username_unique": { + "name": "users_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + }, + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + }, + "users_cpf_unique": { + "name": "users_cpf_unique", + "nullsNotDistinct": false, + "columns": [ + "cpf" + ] + }, + "users_user_stats_id_unique": { + "name": "users_user_stats_id_unique", + "nullsNotDistinct": false, + "columns": [ + "user_stats_id" + ] + } + } + } + }, + "enums": { + "public.complaints_state": { + "name": "complaints_state", + "schema": "public", + "values": [ + "complained", + "rejected", + "accepted" + ] + }, + "public.resource_state": { + "name": "resource_state", + "schema": "public", + "values": [ + "draft", + "submitted", + "accepted", + "reported", + "deleted" + ] + }, + "public.review_state": { + "name": "review_state", + "schema": "public", + "values": [ + "active", + "inactive", + "under_review" + ] + } + }, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index c7618af73a1771de6f0bde0de1110960f8bd424a..4355a4c8a36d4131024a07f496ff01bbf610efaa 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -15,6 +15,13 @@ "when": 1743689366285, "tag": "0001_milky_annihilus", "breakpoints": true + }, + { + "idx": 2, + "version": "7", + "when": 1744642373950, + "tag": "0002_melodic_baron_strucker", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/db/repo/resource.repo.ts b/src/db/repo/resource.repo.ts index 03d2bc374b2c711bbaa04440de63b1f8979249f4..8418ce48a008aeb411715d3c4afed127ee501002 100644 --- a/src/db/repo/resource.repo.ts +++ b/src/db/repo/resource.repo.ts @@ -8,6 +8,7 @@ import { eq, sql, and } from 'drizzle-orm' export class ResourceRepo { async create(resource: ResourceInput ): Promise<ResourceModel> { + console.log("Teste do resource: ", resource) const [ret] = await db .insert(resourceTable) .values(resource) diff --git a/src/db/repo/user-role.repo.ts b/src/db/repo/user-role.repo.ts index 2aead5309c3498ce61523d83ba6feddd5d606c08..084c53a5ffc70df7130cd77a7edeb7b3a1220b5c 100644 --- a/src/db/repo/user-role.repo.ts +++ b/src/db/repo/user-role.repo.ts @@ -3,6 +3,8 @@ import { z } from "zod"; import db from "@/db"; import { and, eq } from "drizzle-orm"; import userRoleRelationTable, { userRoleRelationSchemas, type UserRoleRelationInput, type UserRoleRelationModel, type UserRoleRelationUpdate } from "../relations/user-role.relation"; +import { roleTable } from "../schema"; +import type { RoleModel } from "../schema/roles.schema"; @Service() export class UserRoleRepo{ @@ -13,8 +15,15 @@ export class UserRoleRepo{ .parse(await db.query.userRoleRelationTable.findMany()) } + async findInfoByIdRole(id_role: UserRoleRelationModel['role_id']): Promise<RoleModel>{ + const [ret] = await db + .select() + .from(roleTable) + .where(eq(roleTable.id, id_role)) + return ret + } + async findByUserRole(userRoleRelation: UserRoleRelationInput): Promise<number> { - console.log(userRoleRelation) const userRole = await db.query.userRoleRelationTable.findFirst({ where: and(eq(userRoleRelationTable.role_id, userRoleRelation.role_id), eq(userRoleRelationTable.user_id, userRoleRelation.user_id)) }) diff --git a/src/db/schema/resource.schema.ts b/src/db/schema/resource.schema.ts index 7c4d9379d141d317f3deba3d22bdcd95628d20cd..2eb013bec55912fdbd16d9867e4db4d9cab3ecf5 100644 --- a/src/db/schema/resource.schema.ts +++ b/src/db/schema/resource.schema.ts @@ -23,7 +23,7 @@ const resourceTable = pgTable('resources', { id: serial('id').primaryKey() .notNull() .unique(), - state: resourceEnum('resource_state').notNull().default('draft'), + state: resourceEnum('state').notNull().default('draft'), name: varchar('name', { length: 255 }) .notNull(), author: varchar('author', { length: 255 }) @@ -72,23 +72,32 @@ const resourceInputSchema = createInsertSchema(resourceTable) .extend({ resource_stats_id: z.number().optional(), }) - + const resourceUpdateSchema = resourceInputSchema .partial() .required({ id: true }) +const resourceReturnSchema = resourceModelSchema.omit({ + created_at: true, + updated_at: true, + published_at: true, + submitted_at: true, + deleted_at: true, +}) export type ResourceModel = z.infer<typeof resourceModelSchema> export type ResourceDto = z.infer<typeof resourceDtoSchema> export type ResourceInput = z.infer<typeof resourceInputSchema> export type ResourceUpdate = z.infer<typeof resourceUpdateSchema> +export type ResourceReturn = z.infer <typeof resourceReturnSchema> export const resourceSchema = { model: resourceModelSchema, dto: resourceDtoSchema, input: resourceInputSchema, update: resourceUpdateSchema, + return: resourceReturnSchema } export default resourceTable \ No newline at end of file diff --git a/src/db/seed.ts b/src/db/seed.ts index a6e38e36a64d49359310d47217e0d74745b1d9e1..0e8c39b11d03388c916964f6e5d6459ebd13800b 100644 --- a/src/db/seed.ts +++ b/src/db/seed.ts @@ -35,7 +35,7 @@ await seeds.submissionSeed(db) await seeds.languageSeed(db) await seeds.educationalStageSeed(db) await seeds.roleSeed(db) -await seeds.complaintSeed(db) +// await seeds.complaintSeed(db) await seeds.resourceLanguagesSeed(db) await seeds.collectionLikesSeed(db) await seeds.userRoleSeed(db) diff --git a/src/db/seeds/object-type.seed.ts b/src/db/seeds/object-type.seed.ts index 057c22aa0791cb87304db004590b3912180f67dc..4c11de73546c964dd2d51a6446a5dc62137fe1f1 100644 --- a/src/db/seeds/object-type.seed.ts +++ b/src/db/seeds/object-type.seed.ts @@ -7,35 +7,97 @@ export default async function seed(db: db) { } + + const objectTypeData: ObjectTypeInput[] = [ { - name: 'Book', + name: 'Imagem', + }, + { + name: 'Mapa', + }, + { + name: 'Software Educacional', + }, + { + name: 'Experimento Prático', + }, + { + name: 'Texto', + }, + { + name: 'Áudio', + }, + { + name: 'Vídeo', + }, + { + name: 'Animação', + }, + { + name: 'Plano de Aula', + }, + { + name: 'Website Externo', + }, + { + name: 'Apresentação', + }, + { + name: 'Infrográfico', + }, + { + name: 'Jogo', + }, + { + name: 'Aplicativo Móvel', + }, + { + name: 'Livro Digital', + }, + { + name: 'Imagem', + }, + { + name: 'Mapa', + }, + { + name: 'Software Educacional', + }, + { + name: 'Experimento Prático', + }, + { + name: 'Texto', + }, + { + name: 'Áudio', }, { - name: 'Article', + name: 'Vídeo', }, { - name: 'Video', + name: 'Animação', }, { - name: 'Audio', + name: 'Plano de Aula', }, { - name: 'Image', + name: 'Website Externo', }, { - name: 'Software', + name: 'Apresentação', }, { - name: 'Dataset', + name: 'Infrográfico', }, { - name: 'Presentation', + name: 'Jogo', }, { - name: 'Document', + name: 'Aplicativo Móvel', }, { - name: 'Other', + name: 'Livro Digital', } ] \ No newline at end of file diff --git a/src/db/seeds/subjects.seed.ts b/src/db/seeds/subjects.seed.ts index 80a1ffd235ce3a81f006fed6117ae032d429ce45..748f30cbe731119c03bcfb24b48c651ea7a2bacb 100644 --- a/src/db/seeds/subjects.seed.ts +++ b/src/db/seeds/subjects.seed.ts @@ -43,6 +43,196 @@ const subjectsData: SubjectInput[] = [ { name: 'Filosofia' }, + { + name: 'Sociologia' + },{ + name: 'Matemática' + }, + { + name: 'Português' + }, + { + name: 'História' + }, + { + name: 'Geografia' + }, + { + name: 'Biologia' + }, + { + name: 'Física' + }, + { + name: 'Química' + }, + { + name: 'Inglês' + }, + { + name: 'Espanhol' + }, + { + name: 'Artes' + }, + { + name: 'Educação Física' + }, + { + name: 'Filosofia' + }, + { + name: 'Sociologia' + },{ + name: 'Matemática' + }, + { + name: 'Português' + }, + { + name: 'História' + }, + { + name: 'Geografia' + }, + { + name: 'Biologia' + }, + { + name: 'Física' + }, + { + name: 'Química' + }, + { + name: 'Inglês' + }, + { + name: 'Espanhol' + }, + { + name: 'Artes' + }, + { + name: 'Educação Física' + }, + { + name: 'Filosofia' + }, + { + name: 'Sociologia' + },{ + name: 'Matemática' + }, + { + name: 'Português' + }, + { + name: 'História' + }, + { + name: 'Geografia' + }, + { + name: 'Biologia' + }, + { + name: 'Física' + }, + { + name: 'Química' + }, + { + name: 'Inglês' + }, + { + name: 'Espanhol' + }, + { + name: 'Artes' + }, + { + name: 'Educação Física' + }, + { + name: 'Filosofia' + }, + { + name: 'Sociologia' + },{ + name: 'Matemática' + }, + { + name: 'Português' + }, + { + name: 'História' + }, + { + name: 'Geografia' + }, + { + name: 'Biologia' + }, + { + name: 'Física' + }, + { + name: 'Química' + }, + { + name: 'Inglês' + }, + { + name: 'Espanhol' + }, + { + name: 'Artes' + }, + { + name: 'Educação Física' + }, + { + name: 'Filosofia' + }, + { + name: 'Sociologia' + },{ + name: 'Matemática' + }, + { + name: 'Português' + }, + { + name: 'História' + }, + { + name: 'Geografia' + }, + { + name: 'Biologia' + }, + { + name: 'Física' + }, + { + name: 'Química' + }, + { + name: 'Inglês' + }, + { + name: 'Espanhol' + }, + { + name: 'Artes' + }, + { + name: 'Educação Física' + }, + { + name: 'Filosofia' + }, { name: 'Sociologia' }, diff --git a/src/routes/comments.route.ts b/src/routes/comments.route.ts index 7a7cac99bc5eb853e509808341c29e4973e593e5..583184cd61a22dd92090142b51c9e98a0b79f317 100644 --- a/src/routes/comments.route.ts +++ b/src/routes/comments.route.ts @@ -37,7 +37,6 @@ export const commentsRouter = honoWithJwt() try { const input = await c.req.valid('json') const comment = commentsSchema.dto.parse(await service.create(input)) - console.log("nao funcioina") await serviceUserStats.updateComments(input.user_id) await serviceStatsResource.updateComments(input.resource_id) diff --git a/src/routes/educational-stage.route.ts b/src/routes/educational-stage.route.ts index 1412263ea1c4d1a2faa8714989947a5307666bc8..e195aa37c5417f61ad53dd3b4ce812fb3ede9088 100644 --- a/src/routes/educational-stage.route.ts +++ b/src/routes/educational-stage.route.ts @@ -93,7 +93,7 @@ export const publicEducationalStageRouter = new Hono() try { const educationalStages = educationalStageSchema.dto.array().parse(await service.findMany()) - return c.json({ educationalStages }) + return c.json( educationalStages ) } catch (e) { return c.json( createApexError({ diff --git a/src/routes/language.route.ts b/src/routes/language.route.ts index ff2c4e29d810c48bee2aaf18bf28695fd0799f6c..37ebf6eb1f8111a3308262f633555d3d4be5db0c 100644 --- a/src/routes/language.route.ts +++ b/src/routes/language.route.ts @@ -93,7 +93,7 @@ export const publicLanguageRouter = new Hono() async (c) => { try { const languages = await service.findMany() - return c.json({ languages }) + return c.json( languages ) } catch (e) { return c.json( createApexError({ diff --git a/src/routes/resource.route.ts b/src/routes/resource.route.ts index 78b30b5be50be13581bb8a945850ec00b282905e..336c04394a1e3deaf99f6f1b9f0f7461e81b788f 100644 --- a/src/routes/resource.route.ts +++ b/src/routes/resource.route.ts @@ -27,7 +27,8 @@ import { getResourceByIdRoute, downloadResourceRoute } from "../documentation/resourceDescriber" - +import { z } from "zod"; + const service = Container.get(ResourceService); const serviceStats = Container.get(ResourceStatsService); @@ -43,6 +44,43 @@ type ResourceWithObjectTypeName = ResourceModel & { objectTypeName: string; }; + + + + +export const resourceSchemaJson = { + update: z.object({ + id: z.number().int(), // O id é obrigatório para atualizar o recurso + name: z.string().min(1).max(100).optional(), + description: z.string().min(1).max(1500).optional(), + object_type_id: z.number().int().optional(), + license_id: z.number().int().optional(), + author: z.string().optional(), + subjects: z.array(z.number()), + language: z.array(z.number()), + educational_stages: z.array(z.number()), + user_id: z.number(), + link: z.string().optional().nullable(), + thumbnail:z.string().optional().nullable(), + state: z.enum(['draft', 'submitted', 'accepted', 'reported', 'deleted']).optional(), + resource_stats_id: z.number().optional(), + }), + input: z.object({ + name: z.string().min(1).max(100), + description: z.string().min(1).max(1500), + object_type_id: z.number().int(), + license_id: z.number().int(), + author: z.string().optional(), + subjects: z.array(z.number()), + language: z.array(z.number()), + educational_stages: z.array(z.number()), + user_id: z.number().optional(), + state: z.enum(['draft', 'submitted', 'accepted', 'reported', 'deleted']).optional(), + resource_stats_id: z.number().optional(), + }) +}; + + //funcao para adicionar o nome do objectType a um array de recursos export async function addObjectTypeNameArray(resources: ResourceModel[]): Promise<ResourceWithObjectTypeName[]> { return Promise.all(resources.map(async (resource) => { @@ -77,13 +115,20 @@ async function addObjectTypeNameToResource(resource: ResourceModel): Promise<Res export const resourceRouter = honoWithJwt() - // create a resource + // create a resource, nao precisa mandar o id do usuario dono .post('/create', createResourceRoute, - zValidator('json', resourceSchema.input), + zValidator('json', resourceSchemaJson.input), async (c) => { + const user_id = c.get('jwtPayload').id; try { - const input = c.req.valid('json') + let input = c.req.valid('json') + + input = { + ...input, + user_id: user_id, + state: 'draft', + } //cria o stats do recurso correspondente const stats = resourceStatsSchema.dto.parse( @@ -92,13 +137,40 @@ export const resourceRouter = honoWithJwt() input.resource_stats_id = stats.id + //cria o recurso principal const resource = resourceSchema.dto.parse( await service.create(input) ) - await searchService.indexResource(resource.id) + // associa tudo em paralelo + await Promise.all([ + resourceSubjectsService.associateResourceWithSubjects(resource.id, input.subjects), + resourceLanguagesService.associateResourceWithLanguages(resource.id, input.language), + resourceEducationalStagesService.associateResourceWithEducationalStages(resource.id, input.educational_stages), + ]); + + // 3. Busca os dados relacionados + const [subjects, languages, educationalStages] = await Promise.all([ + resourceSubjectsService.getSubjectsByResource(resource.id), + resourceLanguagesService.getLanguagesByResource(resource.id), + resourceEducationalStagesService.getEducationalStagesByResource(resource.id), + ]); + + + // 4. Extrai apenas os IDs + const subjectIds = subjects.map((s) => s.id); + const languageIds = languages.map((l) => l.id); + const educationalStageIds = educationalStages.map((e) => e.id); + + // 5. Retorna o recurso com os arrays de IDs + return c.json({ + ...resourceSchema.return.parse(resource), + subjects: subjectIds, + language: languageIds, + educational_stages: educationalStageIds, + }); + - return c.json({ resource, stats }) } catch (e) { return c.json( createApexError({ @@ -117,15 +189,41 @@ export const resourceRouter = honoWithJwt() // update a resource .post('/update', updateResourceRoute, - zValidator('json', resourceSchema.update), + zValidator('json', resourceSchemaJson.update), async (c) => { try { const input = c.req.valid('json') const resource = resourceSchema.dto.parse(await service.update(input)) - await searchService.indexResource(resource.id) - return c.json({ resource }) + // Atualiza as associações usando os métodos que você já tem + await Promise.all([ + resourceSubjectsService.updateResourceSubjects(input.id, input.subjects), + resourceLanguagesService.updateResourceLanguages(input.id, input.language ?? []), + resourceEducationalStagesService.updateResourceEducationalStages(input.id, input.educational_stages ?? []), + ]); + + // 3. Busca os dados relacionados + const [subjects, languages, educationalStages] = await Promise.all([ + resourceSubjectsService.getSubjectsByResource(resource.id), + resourceLanguagesService.getLanguagesByResource(resource.id), + resourceEducationalStagesService.getEducationalStagesByResource(resource.id), + ]); + + + // 4. Extrai apenas os IDs + const subjectIds = subjects.map((s) => s.id); + const languageIds = languages.map((l) => l.id); + const educationalStagesId = educationalStages.map((e) => e.id); + //educational stage retorna o objeto inteiro + + // 5. Retorna o recurso com os arrays de IDs + return c.json({ + ...resourceSchema.return.parse(resource), + subjects: subjectIds, + language: languageIds, + educational_stages: educationalStagesId, + }); } catch (e) { return c.json( createApexError({ @@ -364,7 +462,7 @@ export const publicResourceRouter = new Hono() - .get("/download/:id", downloadResourceRoute, async (ctx) => { + .get("/download/:id", downloadResourceRoute, async (ctx) => { const id = ctx.req.param("id"); try { diff --git a/src/routes/s3.route.ts b/src/routes/s3.route.ts index 6cf343977903b06e7295da502a13550417619ea9..dd52c9224c7631474187d54678c1c800cad30605 100644 --- a/src/routes/s3.route.ts +++ b/src/routes/s3.route.ts @@ -38,7 +38,7 @@ export const s3Routes = new Hono() //rota de enviar blob para o s3 //id_ resource é o id do recurso //faz o upload do conteudo do recurso - .post('/upload/resource', uploadResourceRoute, + .post('/upload/resource', uploadResourceRoute, zValidator('form', resourceUploadSchema), async (ctx) => { const formData = await ctx.req.formData(); const fileBlob = formData.get('file'); @@ -81,7 +81,7 @@ export const s3Routes = new Hono() ) // envio de fotos de thumbnail do recurso - .post('/upload/thumbnail/resource', uploadThumbnailResourceRoute, zValidator('json',resourceUploadSchema ), + .post('/upload/thumbnail/resource', uploadThumbnailResourceRoute, zValidator('form', resourceUploadSchema), async (ctx) => { const formData = await ctx.req.formData(); const fileBlob = formData.get('file'); @@ -125,7 +125,7 @@ export const s3Routes = new Hono() // envio de fotos de thumbnail da coleção - .post('/upload/thumbnail/collection', uploadThumbnailCollectionRoute, zValidator('json',collectionUploadSchema ), + .post('/upload/thumbnail/collection', uploadThumbnailCollectionRoute, zValidator('form',collectionUploadSchema ), async (ctx) => { const formData = await ctx.req.formData(); @@ -171,7 +171,7 @@ export const s3Routes = new Hono() // envio de fotos de thumbnail da coleção - .post('/upload/avatar', uploadAvatarRoute, zValidator('json', userUploadSchema ), + .post('/upload/avatar', uploadAvatarRoute, zValidator('form', userUploadSchema ), async (ctx) => { const formData = await ctx.req.formData(); const fileBlob = formData.get('file'); diff --git a/src/routes/user.route.ts b/src/routes/user.route.ts index 51bad6245337226ef9088727496ad6391245d10f..e624f1e02d1611ff87acaa4480568c5e8c5a3285 100644 --- a/src/routes/user.route.ts +++ b/src/routes/user.route.ts @@ -24,8 +24,10 @@ import { systemDeleteUserRoute, meUserRoute } from "../documentation/userDescriber" +import { UserRoleRelationService } from '@/services/user-role.relation.service' const service = Container.get(UserService) +const serviceRole = Container.get(UserRoleRelationService) const followService = Container.get(FollowRelationService) const userStatsService = Container.get(UserStatsService) const searchService = Container.get(SearchService); @@ -35,10 +37,25 @@ export const userRouter = honoWithJwt() async (c) => { const userId = c.get('jwtPayload').id; try { - const user = userSchemas.userProfileSchema.parse( await service.findById(userId)); + const user = userSchemas.userProfileSchema.parse(await service.findById(userId)); + const relations = await serviceRole.findByUserId(userId); + + const roles = ( + await Promise.all( + relations.map(async (rel) => { + const r = await serviceRole.findInfoByIdRole(rel.role_id); + return r.name; + }) + ) + ) + + //retorna usuario com permissoes + const userWithRoles = { + ...user, + roles + } - - return c.json({ user }); + return c.json(userWithRoles); } catch { return c.json( createApexError({ diff --git a/src/services/user-role.relation.service.ts b/src/services/user-role.relation.service.ts index 15cac40f9193c4c04ba4f4c6ff1b8fb555a6f67e..48800cb6b7d16c1ff62b874122318f42c2052b55 100644 --- a/src/services/user-role.relation.service.ts +++ b/src/services/user-role.relation.service.ts @@ -5,6 +5,7 @@ import { type UserRoleRelationUpdate } from "@/db/relations/user-role.relation"; import { UserRoleRepo } from "@/db/repo/user-role.repo"; +import type { RoleModel } from "@/db/schema/roles.schema"; import { Inject, Service } from "typedi"; @Service() @@ -18,6 +19,12 @@ export class UserRoleRelationService { return await this.repo.findMany() } + async findInfoByIdRole( roleId: UserRoleRelationModel['role_id']): Promise<RoleModel>{ + + return await this.repo.findInfoByIdRole(roleId) + } + + async findByUserRole(userRoleRelation: UserRoleRelationInput): Promise<number> { return await this.repo.findByUserRole(userRoleRelation)