diff --git a/docker-compose.yml b/docker-compose.yml old mode 100644 new mode 100755 diff --git a/package.json b/package.json index 121a3023a0c7dd17373c2763881f90bd930b5abc..dfb0d0a2239c1375978be26cce4a602012758da3 100644 --- a/package.json +++ b/package.json @@ -30,5 +30,6 @@ "globals": "^15.6.0", "prettier": "^3.3.2", "typescript-eslint": "^7.14.1" - } -} \ No newline at end of file + }, + "packageManager": "pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1" +} diff --git a/src/db/migrations/0000_sour_wiccan.sql b/src/db/migrations/0000_sour_wiccan.sql deleted file mode 100644 index 115b10d48767cdd25b78b42cfe2704632abe12d1..0000000000000000000000000000000000000000 --- a/src/db/migrations/0000_sour_wiccan.sql +++ /dev/null @@ -1,17 +0,0 @@ -CREATE TABLE IF NOT EXISTS "resource" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(256) NOT NULL, - "author" varchar(256) NOT NULL, - "description" varchar(256), - "bucket_key" varchar(256), - "link" varchar(256), - "thumbnail" varchar(256), - "published_at" timestamp, - "submited_at" timestamp, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp, - "deleted_at" timestamp, - CONSTRAINT "resource_id_unique" UNIQUE("id"), - CONSTRAINT "resource_bucket_key_unique" UNIQUE("bucket_key"), - CONSTRAINT "resource_link_unique" UNIQUE("link") -); diff --git a/src/db/migrations/0001_cold_preak.sql b/src/db/migrations/0001_cold_preak.sql deleted file mode 100644 index 8c8edeb08c62588a27c5b8712f5a253acd5575d5..0000000000000000000000000000000000000000 --- a/src/db/migrations/0001_cold_preak.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "resource" DROP CONSTRAINT "resource_link_unique"; \ No newline at end of file diff --git a/src/db/migrations/0002_uneven_blue_blade.sql b/src/db/migrations/0002_uneven_blue_blade.sql deleted file mode 100644 index 6de3d4da3012d37fc12070d3a0adda480e0f283e..0000000000000000000000000000000000000000 --- a/src/db/migrations/0002_uneven_blue_blade.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE IF NOT EXISTS "stats_resources" ( - "id" serial PRIMARY KEY NOT NULL, - "resource_id" bigint NOT NULL, - "views" bigint DEFAULT 0 NOT NULL, - "downloads" bigint DEFAULT 0 NOT NULL, - "shares" bigint DEFAULT 0 NOT NULL, - "score" bigint DEFAULT 0 NOT NULL, - CONSTRAINT "stats_resources_id_unique" UNIQUE("id") -); ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "stats_resources" ADD CONSTRAINT "stats_resources_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE no action ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; diff --git a/src/db/migrations/0003_polite_wallflower.sql b/src/db/migrations/0003_polite_wallflower.sql deleted file mode 100644 index 0ab81cb61edfb83db1a9fafec380c513dafd6d09..0000000000000000000000000000000000000000 --- a/src/db/migrations/0003_polite_wallflower.sql +++ /dev/null @@ -1,7 +0,0 @@ -ALTER TABLE "stats_resources" DROP CONSTRAINT "stats_resources_resource_id_resource_id_fk"; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "stats_resources" ADD CONSTRAINT "stats_resources_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; diff --git a/src/db/migrations/0004_confused_maestro.sql b/src/db/migrations/0004_confused_maestro.sql deleted file mode 100644 index 83480b9d5beff2295d3c2b82417efc6e64d4e28f..0000000000000000000000000000000000000000 --- a/src/db/migrations/0004_confused_maestro.sql +++ /dev/null @@ -1,44 +0,0 @@ -CREATE TABLE IF NOT EXISTS "user_stats" ( - "id" serial PRIMARY KEY NOT NULL, - "user_id" integer NOT NULL, - "score" integer DEFAULT 0 NOT NULL, - "likes" integer DEFAULT 0, - "likes_received" integer DEFAULT 0, - "follows" integer DEFAULT 0, - "followers" integer DEFAULT 0, - "collections" integer DEFAULT 0, - "submitted_resources" integer DEFAULT 0, - "approved_resources" integer DEFAULT 0, - "reviewed_resources" integer DEFAULT 0, - "comments" integer DEFAULT 0, - CONSTRAINT "user_stats_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "user" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255) NOT NULL, - "username" varchar(255) NOT NULL, - "password" varchar(255) NOT NULL, - "email" varchar(255) NOT NULL, - "description" text DEFAULT 'sem descrição', - "institution" text DEFAULT 'sem instituição', - "birthday" timestamp NOT NULL, - "cpf" varchar(255) NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - "confirmed_at" timestamp, - "confirmation_sent_at" timestamp, - "deleted_at" timestamp, - "reactivated_at" timestamp, - "active" boolean DEFAULT true, - CONSTRAINT "user_id_unique" UNIQUE("id"), - CONSTRAINT "user_username_unique" UNIQUE("username"), - CONSTRAINT "user_email_unique" UNIQUE("email") -); ---> statement-breakpoint -ALTER TABLE "resource" ADD COLUMN "active" boolean DEFAULT false NOT NULL;--> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_stats" ADD CONSTRAINT "user_stats_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; diff --git a/src/db/migrations/meta/0000_snapshot.json b/src/db/migrations/meta/0000_snapshot.json deleted file mode 100644 index a056892a18ff9cfa54c4748fd6a9ebc14a524705..0000000000000000000000000000000000000000 --- a/src/db/migrations/meta/0000_snapshot.json +++ /dev/null @@ -1,120 +0,0 @@ -{ - "id": "d056d734-9ee3-4857-a457-3345dfee2eb3", - "prevId": "00000000-0000-0000-0000-000000000000", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.resource": { - "name": "resource", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "author": { - "name": "author", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "bucket_key": { - "name": "bucket_key", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "link": { - "name": "link", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "thumbnail": { - "name": "thumbnail", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "published_at": { - "name": "published_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "submited_at": { - "name": "submited_at", - "type": "timestamp", - "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": false - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_id_unique": { - "name": "resource_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "resource_bucket_key_unique": { - "name": "resource_bucket_key_unique", - "nullsNotDistinct": false, - "columns": [ - "bucket_key" - ] - }, - "resource_link_unique": { - "name": "resource_link_unique", - "nullsNotDistinct": false, - "columns": [ - "link" - ] - } - } - } - }, - "enums": {}, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0001_snapshot.json b/src/db/migrations/meta/0001_snapshot.json deleted file mode 100644 index bca6aab62f647eca45301bd09477d2aded1c882d..0000000000000000000000000000000000000000 --- a/src/db/migrations/meta/0001_snapshot.json +++ /dev/null @@ -1,113 +0,0 @@ -{ - "id": "3101cbe2-f05b-4013-aba3-12937a639573", - "prevId": "d056d734-9ee3-4857-a457-3345dfee2eb3", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.resource": { - "name": "resource", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "author": { - "name": "author", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "bucket_key": { - "name": "bucket_key", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "link": { - "name": "link", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "thumbnail": { - "name": "thumbnail", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "published_at": { - "name": "published_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "submited_at": { - "name": "submited_at", - "type": "timestamp", - "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": false - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_id_unique": { - "name": "resource_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "resource_bucket_key_unique": { - "name": "resource_bucket_key_unique", - "nullsNotDistinct": false, - "columns": [ - "bucket_key" - ] - } - } - } - }, - "enums": {}, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0002_snapshot.json b/src/db/migrations/meta/0002_snapshot.json deleted file mode 100644 index 31364da7f147a379d1c00f35b1287b3fc46d8a9b..0000000000000000000000000000000000000000 --- a/src/db/migrations/meta/0002_snapshot.json +++ /dev/null @@ -1,185 +0,0 @@ -{ - "id": "00cc062c-c0ff-40e9-8752-4d10b45c3573", - "prevId": "3101cbe2-f05b-4013-aba3-12937a639573", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.resource": { - "name": "resource", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "author": { - "name": "author", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "bucket_key": { - "name": "bucket_key", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "link": { - "name": "link", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "thumbnail": { - "name": "thumbnail", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "published_at": { - "name": "published_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "submited_at": { - "name": "submited_at", - "type": "timestamp", - "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": false - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_id_unique": { - "name": "resource_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "resource_bucket_key_unique": { - "name": "resource_bucket_key_unique", - "nullsNotDistinct": false, - "columns": [ - "bucket_key" - ] - } - } - }, - "public.stats_resources": { - "name": "stats_resources", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "resource_id": { - "name": "resource_id", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "views": { - "name": "views", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "downloads": { - "name": "downloads", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "shares": { - "name": "shares", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "score": { - "name": "score", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "stats_resources_resource_id_resource_id_fk": { - "name": "stats_resources_resource_id_resource_id_fk", - "tableFrom": "stats_resources", - "tableTo": "resource", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "stats_resources_id_unique": { - "name": "stats_resources_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - } - }, - "enums": {}, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0003_snapshot.json b/src/db/migrations/meta/0003_snapshot.json deleted file mode 100644 index 1259293ec3a503e9e3f29b10d1609471e1b65719..0000000000000000000000000000000000000000 --- a/src/db/migrations/meta/0003_snapshot.json +++ /dev/null @@ -1,185 +0,0 @@ -{ - "id": "ed42f7cb-45e7-47c8-93d7-a35abfc74f5a", - "prevId": "00cc062c-c0ff-40e9-8752-4d10b45c3573", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.resource": { - "name": "resource", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "author": { - "name": "author", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "bucket_key": { - "name": "bucket_key", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "link": { - "name": "link", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "thumbnail": { - "name": "thumbnail", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "published_at": { - "name": "published_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "submited_at": { - "name": "submited_at", - "type": "timestamp", - "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": false - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_id_unique": { - "name": "resource_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "resource_bucket_key_unique": { - "name": "resource_bucket_key_unique", - "nullsNotDistinct": false, - "columns": [ - "bucket_key" - ] - } - } - }, - "public.stats_resources": { - "name": "stats_resources", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "resource_id": { - "name": "resource_id", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "views": { - "name": "views", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "downloads": { - "name": "downloads", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "shares": { - "name": "shares", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "score": { - "name": "score", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "stats_resources_resource_id_resource_id_fk": { - "name": "stats_resources_resource_id_resource_id_fk", - "tableFrom": "stats_resources", - "tableTo": "resource", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "stats_resources_id_unique": { - "name": "stats_resources_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - } - }, - "enums": {}, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0004_snapshot.json b/src/db/migrations/meta/0004_snapshot.json deleted file mode 100644 index ec6a83a600e0cad2c1a9c0922159de9248299afc..0000000000000000000000000000000000000000 --- a/src/db/migrations/meta/0004_snapshot.json +++ /dev/null @@ -1,439 +0,0 @@ -{ - "id": "1ab52913-6a40-4df5-b569-1fd63fb22a9a", - "prevId": "ed42f7cb-45e7-47c8-93d7-a35abfc74f5a", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.resource": { - "name": "resource", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "author": { - "name": "author", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "bucket_key": { - "name": "bucket_key", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "link": { - "name": "link", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "thumbnail": { - "name": "thumbnail", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "active": { - "name": "active", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "published_at": { - "name": "published_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "submited_at": { - "name": "submited_at", - "type": "timestamp", - "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": false - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_id_unique": { - "name": "resource_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "resource_bucket_key_unique": { - "name": "resource_bucket_key_unique", - "nullsNotDistinct": false, - "columns": [ - "bucket_key" - ] - } - } - }, - "public.stats_resources": { - "name": "stats_resources", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "resource_id": { - "name": "resource_id", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "views": { - "name": "views", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "downloads": { - "name": "downloads", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "shares": { - "name": "shares", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "score": { - "name": "score", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "stats_resources_resource_id_resource_id_fk": { - "name": "stats_resources_resource_id_resource_id_fk", - "tableFrom": "stats_resources", - "tableTo": "resource", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "stats_resources_id_unique": { - "name": "stats_resources_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_stats": { - "name": "user_stats", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "score": { - "name": "score", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "likes": { - "name": "likes", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "likes_received": { - "name": "likes_received", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "follows": { - "name": "follows", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "followers": { - "name": "followers", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "collections": { - "name": "collections", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "submitted_resources": { - "name": "submitted_resources", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "approved_resources": { - "name": "approved_resources", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "reviewed_resources": { - "name": "reviewed_resources", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "comments": { - "name": "comments", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "user_stats_user_id_user_id_fk": { - "name": "user_stats_user_id_user_id_fk", - "tableFrom": "user_stats", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_stats_id_unique": { - "name": "user_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user": { - "name": "user", - "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'" - }, - "institution": { - "name": "institution", - "type": "text", - "primaryKey": false, - "notNull": false, - "default": "'sem instituição'" - }, - "birthday": { - "name": "birthday", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "cpf": { - "name": "cpf", - "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()" - }, - "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 - }, - "active": { - "name": "active", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_id_unique": { - "name": "user_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "user_username_unique": { - "name": "user_username_unique", - "nullsNotDistinct": false, - "columns": [ - "username" - ] - }, - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": {}, - "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 deleted file mode 100644 index e06c040e2a31683c19d76df177495da3962db53d..0000000000000000000000000000000000000000 --- a/src/db/migrations/meta/_journal.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "7", - "dialect": "postgresql", - "entries": [ - { - "idx": 0, - "version": "7", - "when": 1726578459970, - "tag": "0000_sour_wiccan", - "breakpoints": true - }, - { - "idx": 1, - "version": "7", - "when": 1726581044222, - "tag": "0001_cold_preak", - "breakpoints": true - }, - { - "idx": 2, - "version": "7", - "when": 1726669420370, - "tag": "0002_uneven_blue_blade", - "breakpoints": true - }, - { - "idx": 3, - "version": "7", - "when": 1726750555860, - "tag": "0003_polite_wallflower", - "breakpoints": true - }, - { - "idx": 4, - "version": "7", - "when": 1727099258603, - "tag": "0004_confused_maestro", - "breakpoints": true - } - ] -} \ No newline at end of file diff --git a/src/db/repo/client.repo.ts b/src/db/repo/client.repo.ts deleted file mode 100644 index c2eecfbe026428e79bc4bf89ef4e138bce2d888e..0000000000000000000000000000000000000000 --- a/src/db/repo/client.repo.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { Service } from 'typedi' -import type { - ClientInput, - ClientModel, - ClientUpdate, -} from '../schema/client.model' -import db from '..' -import clientTable, { clientSchemas } from '../schema/client.model' -import { eq } from 'drizzle-orm' - -@Service() -export class ClientRepo { - async create(client: ClientInput): Promise<ClientModel> { - const [ret] = await db - .insert(clientTable) - .values(client) - .returning() - - return clientSchemas.clientModelSchema.parse(ret) - } - - async update(client: ClientUpdate): Promise<ClientModel> { - const [ret] = await db - .update(clientTable) - .set(client) - .where(eq(clientTable.id, client.id)) - .returning() - - return clientSchemas.clientModelSchema.parse(ret) - } - - async delete(id: ClientModel['id']): Promise<ClientModel> { - const [ret] = await db - .delete(clientTable) - .where(eq(clientTable.id, id)) - .returning() - - return clientSchemas.clientModelSchema.parse(ret) - } - - async find( - id: ClientModel['id'] - ): Promise<ClientModel | undefined> { - const client = await db.query.clientTable.findFirst({ - where: eq(clientTable.id, id), - }) - - return clientSchemas.clientModelSchema.parse(client) - } - - async findMany(): Promise<ClientModel[]> { - return clientSchemas.clientModelSchema - .array() - .parse(await db.query.clientTable.findMany()) - } -} diff --git a/src/db/repo/collection-stats.repo.ts b/src/db/repo/collection-stats.repo.ts new file mode 100644 index 0000000000000000000000000000000000000000..5d9039263ab9cbb52160d2f33e83f66e997f7193 --- /dev/null +++ b/src/db/repo/collection-stats.repo.ts @@ -0,0 +1,102 @@ +import { Service } from "typedi"; +import type { + CollectionStatsInput, + CollectionStatsModel, + CollectionStatsUpdate, +} from '../schema/collection-stats.model' +import db from ".."; +import collectionStatsTable, { collectionStatsSchemas } from "../schema/collection-stats.model"; +import { eq, sql } from 'drizzle-orm' + + +@Service() +export class CollectionStatsRepo { + async create(collectionStats: CollectionStatsInput): Promise<CollectionStatsModel> { + const [ret] = await db + .insert(collectionStatsTable) + .values(collectionStats) + .returning() + + return collectionStatsSchemas.collectionStatsModelSchema.parse(ret) + } + + async updateViews(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + + const [ret] = await db + .update(collectionStatsTable) + .set({ views: sql`${collectionStatsTable.views} + 1` }) + .where(eq(collectionStatsTable.id, id)) + .returning(); + + return collectionStatsSchemas.collectionStatsModelSchema.parse(ret); + } + + async updateDownloads(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + const [ret] = await db + .update(collectionStatsTable) + .set({ downloads: sql`${collectionStatsTable.downloads} + 1` }) + .where(eq(collectionStatsTable.id, id)) + .returning(); + + return collectionStatsSchemas.collectionStatsModelSchema.parse(ret); + } + + async updateLikes(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + const [ret] = await db + .update(collectionStatsTable) + .set({ likes: sql`${collectionStatsTable.likes} + 1` }) + .where(eq(collectionStatsTable.id, id)) + .returning(); + + return collectionStatsSchemas.collectionStatsModelSchema.parse(ret); + } + + async updateShares(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + const [ret] = await db + .update(collectionStatsTable) + .set({ shares: sql`${collectionStatsTable.shares} + 1` }) + .where(eq(collectionStatsTable.id, id)) + .returning(); + + return collectionStatsSchemas.collectionStatsModelSchema.parse(ret); + } + + async updateScore(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + const [ret] = await db + .update(collectionStatsTable) + .set({ score: sql`${collectionStatsTable.score} + 1` }) + .where(eq(collectionStatsTable.id, id)) + .returning(); + + return collectionStatsSchemas.collectionStatsModelSchema.parse(ret); + } + + async updateFollows(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + const [ret] = await db + .update(collectionStatsTable) + .set({ follows: sql`${collectionStatsTable.follows} + 1` }) + .where(eq(collectionStatsTable.id, id)) + .returning(); + + return collectionStatsSchemas.collectionStatsModelSchema.parse(ret); + } + + async delete(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + const [ret] = await db + .delete(collectionStatsTable) + .where(eq(collectionStatsTable.id, id)) + .returning() + + return collectionStatsSchemas.collectionStatsModelSchema.parse(ret) + } + + async find( + id: CollectionStatsModel['id'] + ): Promise<CollectionStatsModel | undefined> { + const collectionStats = await db.query.collectionStatsTable.findFirst({ + where: eq(collectionStatsTable.id, id), + }) + + return collectionStatsSchemas.collectionStatsModelSchema.parse(collectionStats) + } +} \ No newline at end of file diff --git a/src/db/repo/collections.repo.ts b/src/db/repo/collections.repo.ts new file mode 100644 index 0000000000000000000000000000000000000000..58300b223fa3abfffdd7ee82290ad3a12ee51171 --- /dev/null +++ b/src/db/repo/collections.repo.ts @@ -0,0 +1,81 @@ +import { Service } from "typedi"; +import type { + CollectionInput, + CollectionModel, + CollectionUpdate, +} from '../schema/collections.model' +import db from ".."; +import collectionTable, { collectionSchemas } from "../schema/collections.model"; +import { eq } from 'drizzle-orm' + +@Service() +export class CollectionRepo { + async create(collection: CollectionInput): Promise<CollectionModel> { + const [ret] = await db + .insert(collectionTable) + .values(collection) + .returning() + + return collectionSchemas.collectionModelSchema.parse(ret) + } + + async update(collection: CollectionUpdate): Promise<CollectionModel> { + + collection.updated_at = new Date().toISOString(); + + const [ret] = await db + .update(collectionTable) + .set(collection) + .where(eq(collectionTable.id, collection.id)) + .returning() + + return collectionSchemas.collectionModelSchema.parse(ret) + } + + async delete(id: CollectionModel['id']): Promise<CollectionModel> { + + const [ret] = await db + .update(collectionTable) + .set({ deleted_at: new Date().toISOString(), is_active: false }) + .where(eq(collectionTable.id, id)) + .returning(); + + return collectionSchemas.collectionModelSchema.parse(ret) + } + + async deletePermanently(id: CollectionModel['id']): Promise<CollectionModel> { + const [ret] = await db + .delete(collectionTable) + .where(eq(collectionTable.id, id)) + .returning() + + return collectionSchemas.collectionModelSchema.parse(ret) + } + + async restore(id: CollectionModel['id']): Promise<CollectionModel> { + const [ret] = await db + .update(collectionTable) + .set({ deleted_at: null, is_active: true }) + .where(eq(collectionTable.id, id)) + .returning() + + return collectionSchemas.collectionModelSchema.parse(ret) + } + + async find( + id: CollectionModel['id'] + ): Promise<CollectionModel | undefined> { + const collection = await db.query.collectionTable.findFirst({ + where: eq(collectionTable.id, id), + }) + + if (collection?.deleted_at === null) + return collectionSchemas.collectionModelSchema.parse(collection) + } + + async findMany(): Promise<CollectionModel[]> { + return collectionSchemas.collectionModelSchema + .array() + .parse(await db.query.collectionTable.findMany()) + } +} \ No newline at end of file diff --git a/src/db/repo/credit-card.repo.ts b/src/db/repo/credit-card.repo.ts deleted file mode 100644 index 460eec6709e19b38142add7ce9de412e6c1c289a..0000000000000000000000000000000000000000 --- a/src/db/repo/credit-card.repo.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { Service } from 'typedi' -import type { - CreditCardInput, - CreditCardModel, - CreditCardUpdate, -} from '../schema/credit-card.model' -import creditCardTable, { - creditCardSchemas, -} from '../schema/credit-card.model' -import db from '..' -import { eq } from 'drizzle-orm' - -@Service() -export class CreditCardRepo { - async create( - creditCard: CreditCardInput - ): Promise<CreditCardModel> { - const [ret] = await db - .insert(creditCardTable) - .values(creditCard) - .returning() - - return creditCardSchemas.creditCardModelSchema.parse(ret) - } - - async update( - creditCard: CreditCardUpdate - ): Promise<CreditCardModel> { - const [ret] = await db - .update(creditCardTable) - .set(creditCard) - .where(eq(creditCardTable.id, creditCard.id)) - .returning() - - return creditCardSchemas.creditCardModelSchema.parse(ret) - } - - async delete(id: CreditCardModel['id']): Promise<CreditCardModel> { - const [ret] = await db - .delete(creditCardTable) - .where(eq(creditCardTable.id, id)) - .returning() - - return creditCardSchemas.creditCardModelSchema.parse(ret) - } - - async find( - id: CreditCardModel['id'] - ): Promise<CreditCardModel | undefined> { - const creditCard = await db.query.creditCardTable.findFirst({ - where: eq(creditCardTable.id, id), - }) - - return creditCardSchemas.creditCardModelSchema.parse(creditCard) - } - - async findMany(): Promise<CreditCardModel[]> { - return creditCardSchemas.creditCardModelSchema - .array() - .parse(await db.query.creditCardTable.findMany()) - } -} diff --git a/src/db/schema/client.model.ts b/src/db/schema/client.model.ts deleted file mode 100644 index a5a25f917af9e3b135085c7cc1986a8367fc814c..0000000000000000000000000000000000000000 --- a/src/db/schema/client.model.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { relations, sql } from 'drizzle-orm' -import { - pgTable, - timestamp, - uuid, - varchar, -} from 'drizzle-orm/pg-core' -import { createInsertSchema, createSelectSchema } from 'drizzle-zod' -import { z } from 'zod' -import creditCardTable, { - creditCardSchemas, -} from './credit-card.model' - -const clientTable = pgTable('client', { - id: uuid('id').primaryKey().defaultRandom(), - name: varchar('name', { length: 255 }).notNull(), - cnpj: varchar('cnpj', { length: 20 }).unique().notNull(), - industry: varchar('industry', { length: 50 }), - hqAddress: varchar('hq_address', { length: 255 }), - phone: varchar('phone', { length: 20 }), - email: varchar('email', { length: 255 }).unique(), - contactPerson: varchar('contact_person', { length: 255 }), - createdAt: timestamp('created_at', { mode: 'string' }) - .notNull() - .defaultNow(), - updatedAt: timestamp('updated_at', { mode: 'string' }) - .notNull() - .defaultNow() - .$onUpdate(() => sql`current_timestamp`), -}) - -export const clientTableRelations = relations( - clientTable, - ({ many }) => ({ - creditCards: many(creditCardTable), - }) -) - -const clientModelSchema = createSelectSchema(clientTable).extend({ - creditCards: creditCardSchemas.creditCardModelSchema - .array() - .optional(), -}) -const clientDtoSchema = clientModelSchema -const clientInputSchema = createInsertSchema(clientTable, { - email: (schema) => schema.email.email(), -}) -const clientUpdateSchema = clientInputSchema - .partial() - .required({ id: true }) - -export type ClientModel = z.infer<typeof clientModelSchema> -export type ClientDto = z.infer<typeof clientDtoSchema> -export type ClientInput = z.infer<typeof clientInputSchema> -export type ClientUpdate = z.infer<typeof clientUpdateSchema> - -export const clientSchemas = { - clientModelSchema, - clientDtoSchema, - clientInputSchema, - clientUpdateSchema, -} - -export default clientTable diff --git a/src/db/schema/collection-stats.model.ts b/src/db/schema/collection-stats.model.ts new file mode 100644 index 0000000000000000000000000000000000000000..ccc506cdd7b8d1324e00564963c6ff4a94c98aef --- /dev/null +++ b/src/db/schema/collection-stats.model.ts @@ -0,0 +1,38 @@ +import { + pgTable, + serial, + bigint + } from 'drizzle-orm/pg-core' + import { createInsertSchema, createSelectSchema } from 'drizzle-zod' + import { z } from 'zod' +import collectionTable from './collections.model' + + const collectionStatsTable = pgTable('collection_stats', { + id: serial('id').primaryKey().notNull().unique(), + collectionId: bigint('collection_id', {mode: 'number'}).notNull().references(() => collectionTable.id, {onDelete: 'cascade'}), + views: bigint('views', {mode: 'number'}).default(0), + downloads: bigint('downloads', {mode: 'number'}).default(0), + likes: bigint('likes', {mode: 'number'}).default(0), + shares: bigint('shares', {mode: 'number'}).default(0), + score: bigint('score', {mode: 'number'}).default(0), + follows: bigint('follows', {mode: 'number'}).default(0), + }) + + const collectionStatsModelSchema = createSelectSchema(collectionStatsTable) + const collectionStatsDtoSchema = collectionStatsModelSchema + const collectionStatsInputSchema = createInsertSchema(collectionStatsTable) + const collectionStatsUpdateSchema = collectionStatsInputSchema.partial().required({ id: true }) + +export type CollectionStatsModel = z.infer<typeof collectionStatsModelSchema> +export type CollectionStatsDto = z.infer<typeof collectionStatsDtoSchema> +export type CollectionStatsInput = z.infer<typeof collectionStatsInputSchema> +export type CollectionStatsUpdate = z.infer<typeof collectionStatsUpdateSchema> + +export const collectionStatsSchemas = { + collectionStatsModelSchema, + collectionStatsDtoSchema, + collectionStatsInputSchema, + collectionStatsUpdateSchema, +} + +export default collectionStatsTable \ No newline at end of file diff --git a/src/db/schema/collections.model.ts b/src/db/schema/collections.model.ts new file mode 100644 index 0000000000000000000000000000000000000000..1c544ce2b60aa37c5339ce2c9fe39f2cd18b9fdd --- /dev/null +++ b/src/db/schema/collections.model.ts @@ -0,0 +1,41 @@ +import { + boolean, + pgTable, + serial, + text, + timestamp, + varchar, +} from 'drizzle-orm/pg-core' +import { createInsertSchema, createSelectSchema } from 'drizzle-zod' +import { z } from 'zod' + +const collectionTable = pgTable('collection', { + id: serial('id').primaryKey().notNull().unique(), + name: varchar('name', { length: 255 }), + description: text('description'), + is_private: boolean('is_private'), + is_active: boolean('is_active').default(true), + created_at: timestamp('created_at', { mode: 'string' }).notNull().defaultNow(), + updated_at: timestamp('updated_at', { mode: 'string' }), + deleted_at: timestamp('deleted_at', { mode: 'string' }), + thumbnail: varchar('thumbnail', { length: 255 }), +}) + +const collectionModelSchema = createSelectSchema(collectionTable) +const collectionDtoSchema = collectionModelSchema +const collectionInputSchema = createInsertSchema(collectionTable) +const collectionUpdateSchema = collectionInputSchema.partial().required({ id: true }) + +export type CollectionModel = z.infer<typeof collectionModelSchema> +export type CollectionDto = z.infer<typeof collectionDtoSchema> +export type CollectionInput = z.infer<typeof collectionInputSchema> +export type CollectionUpdate = z.infer<typeof collectionUpdateSchema> + +export const collectionSchemas = { + collectionModelSchema, + collectionDtoSchema, + collectionInputSchema, + collectionUpdateSchema, +} + +export default collectionTable \ No newline at end of file diff --git a/src/db/schema/credit-card.model.ts b/src/db/schema/credit-card.model.ts deleted file mode 100644 index 3182b8ae7e9e2f760226b1e41b5ccdc2d6727d5a..0000000000000000000000000000000000000000 --- a/src/db/schema/credit-card.model.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { - date, - pgTable, - timestamp, - uuid, - varchar, -} from 'drizzle-orm/pg-core' -import { createInsertSchema, createSelectSchema } from 'drizzle-zod' -import type { z } from 'zod' -import clientTable from './client.model' -import { relations, sql } from 'drizzle-orm' - -const creditCardTable = pgTable('credit_card', { - id: uuid('id').primaryKey().defaultRandom(), - clientId: uuid('client_id') - .references(() => clientTable.id, { onDelete: 'cascade' }) - .notNull(), - cardNumber: varchar('card_number', { length: 20 }) - .unique() - .notNull(), - cardholderName: varchar('cardholder_name', { - length: 255, - }).notNull(), - expirationDate: date('expiration_date', { - mode: 'string', - }).notNull(), - cvv: varchar('cvv', { length: 5 }).notNull(), - createdAt: timestamp('created_at', { - mode: 'string', - }) - .notNull() - .defaultNow(), - updatedAt: timestamp('updated_at', { - mode: 'string', - }) - .notNull() - .defaultNow() - .$onUpdate(() => sql`current_timestamp`), -}) - -export const creditCardTableRelations = relations( - creditCardTable, - ({ one }) => ({ - client: one(clientTable, { - fields: [creditCardTable.clientId], - references: [clientTable.id], - }), - }) -) - -const creditCardModelSchema = createSelectSchema(creditCardTable) -const creditCardDtoSchema = creditCardModelSchema.omit({ - cvv: true, - cardNumber: true, -}) -const creditCardInputSchema = createInsertSchema(creditCardTable) -const creditCardUpdateSchema = creditCardInputSchema - .partial() - .required({ id: true }) - -export type CreditCardModel = z.infer<typeof creditCardModelSchema> -export type CreditCardDto = z.infer<typeof creditCardDtoSchema> -export type CreditCardInput = z.infer<typeof creditCardInputSchema> -export type CreditCardUpdate = z.infer<typeof creditCardUpdateSchema> - -export const creditCardSchemas = { - creditCardModelSchema, - creditCardDtoSchema, - creditCardInputSchema, - creditCardUpdateSchema, -} - -export default creditCardTable diff --git a/src/db/schema/index.ts b/src/db/schema/index.ts index c0a69e10668c98e2c7d81b3524ad85e347e4ceac..0fb247f075958b3e25297bb7e0e22a478b4df09a 100644 --- a/src/db/schema/index.ts +++ b/src/db/schema/index.ts @@ -3,12 +3,18 @@ import userTable from './user.model' import resourceTable from './resource.schema' import statsResourcesTable from './stats-resources.schema' +import collectionStatsTable from './collection-stats.model' +import collectionTable from './collections.model' + + export { userTable, userStatsTable, resourceTable, - statsResourcesTable + collectionTable, + statsResourcesTable, + collectionStatsTable } export const tables = [ @@ -16,5 +22,10 @@ export const tables = [ userStatsTable, resourceTable, statsResourcesTable, + collectionTable, + collectionStatsTable + ] + + diff --git a/src/db/schema/user.model.ts b/src/db/schema/user.model.ts index 813a23fcaa2b8957f85e41e7f2ba1501b8c51b8a..be6647f4c9e96afd98dfef23dc2924f52e666c58 100644 --- a/src/db/schema/user.model.ts +++ b/src/db/schema/user.model.ts @@ -1,8 +1,7 @@ -import { relations, sql } from 'drizzle-orm' +import { sql } from 'drizzle-orm' import { boolean, pgTable, serial, text, timestamp, varchar } from 'drizzle-orm/pg-core' import { createInsertSchema, createSelectSchema } from 'drizzle-zod' import { z } from 'zod' -import userStatsTable from './user-stats.model' const userTable = pgTable('user', { id: serial('id').primaryKey() @@ -18,10 +17,8 @@ const userTable = pgTable('user', { email: varchar('email', { length: 255 }) .unique() .notNull(), - description: text('description') - .default("sem descrição"), - institution: text('institution') - .default("sem instituição"), + description: text('description'), + institution: text('institution'), birthday: timestamp('birthday', { mode: 'string' }) .notNull(), cpf: varchar('cpf', { length: 255 }) @@ -38,16 +35,8 @@ const userTable = pgTable('user', { deleted_at: timestamp('deleted_at', { mode: 'string' }), reactivated_at: timestamp('reactivated_at', { mode: 'string' }), active: boolean('active') - .default(true) }) -export const userTableRelation = relations( - userTable, - ({ one }) => ({ - userStats: one(userStatsTable) - }) -) - const userInputSchema = createInsertSchema(userTable) const userModelSchema = createSelectSchema(userTable) const userDtoSchema = createSelectSchema(userTable).omit({ diff --git a/src/db/seed.ts b/src/db/seed.ts index 20fb4eeb48f6ee5fefe1af8d1d1eaf4e1f759700..e49fbd4efd170fbccb19ee8ed9bb457f6e1e325f 100644 --- a/src/db/seed.ts +++ b/src/db/seed.ts @@ -25,5 +25,7 @@ await seeds.userSeed(db) await seeds.userStatsSeed(db) await seeds.resourceSeed(db) await seeds.statsResourcesSeed(db) +await seeds.collectionSeed(db) +await seeds.collectionStatsSeed(db) await connection.end() diff --git a/src/db/seeds/collection-stats.seed.ts b/src/db/seeds/collection-stats.seed.ts new file mode 100644 index 0000000000000000000000000000000000000000..6eec4b217a178667d4daeeeca44f742e89a1ba1e --- /dev/null +++ b/src/db/seeds/collection-stats.seed.ts @@ -0,0 +1,38 @@ +import type db from '..' +import type { CollectionStatsInput } from '../schema/collection-stats.model' +import collectionStatsTable from '../schema/collection-stats.model' + +export default async function seed(db:db) { + await db.insert(collectionStatsTable).values(collectionStatsData) +} + +const collectionStatsData: CollectionStatsInput[] = [ + { + collectionId: 1, + views: 100, + downloads: 50, + likes: 20, + shares: 10, + score: 4, + follows: 5, + }, + { + collectionId: 2, + views: 200, + downloads: 100, + likes: 40, + shares: 20, + score: 4, + follows: 10, + }, + { + collectionId: 3, + views: 300, + downloads: 150, + likes: 60, + shares: 30, + score: 4, + follows: 15, + } + +] \ No newline at end of file diff --git a/src/db/seeds/collections.seed.ts b/src/db/seeds/collections.seed.ts new file mode 100644 index 0000000000000000000000000000000000000000..3a26fc4e6f5aedb5d3f39f0ccf599ae3c69e427d --- /dev/null +++ b/src/db/seeds/collections.seed.ts @@ -0,0 +1,28 @@ +import type db from '..' +import type { CollectionInput } from '../schema/collections.model' +import collectionTable from '../schema/collections.model' + +export default async function seed(db:db) { + await db.insert(collectionTable).values(collectionData) +} + +const collectionData: CollectionInput[] = [ + { + name: 'Collection 1', + description: 'Collection 1 description', + is_private: false, + thumbnail: 'https://www.google.com', + }, + { + name: 'Collection 2', + description: 'Collection 2 description', + is_private: true, + thumbnail: 'https://www.google.com', + }, + { + name: 'Collection 3', + description: 'Collection 3 description', + is_private: false, + thumbnail: 'https://www.google.com', + } +] diff --git a/src/db/seeds/index.ts b/src/db/seeds/index.ts index 08cff8c16fd09b3fb7a111a6600ddfcc01206e3d..1f52fb3d507c1068e9e75178aa081815097cad69 100644 --- a/src/db/seeds/index.ts +++ b/src/db/seeds/index.ts @@ -2,3 +2,5 @@ export { default as userSeed } from './user.seed' export { default as userStatsSeed } from './user-stats.seed' export {default as resourceSeed} from './resource.seed' export {default as statsResourcesSeed} from './statsResources.seed' +export { default as collectionSeed } from './collections.seed' +export { default as collectionStatsSeed } from './collection-stats.seed' diff --git a/src/index.ts b/src/index.ts index 1e5c111fee5b7f2562707f8b80231cf7ff76673f..077dc63d35fd9b42ada864816dd4b267c212cd53 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,9 @@ import { Hono } from 'hono' import { logger } from 'hono/logger' - -import { signUpRouter, userRouter } from './routes/user.routes' +import type { AuthPayload } from './db/repo/auth.repo' import { authRouter } from './routes/auth.route' import { jwt } from 'hono/jwt' import env from './env' -import type { AuthPayload } from './db/repo/auth.repo' -import { uploaderRouter } from './routes/uploader.route' import { prettyJSON } from 'hono/pretty-json' import { cors } from 'hono/cors' import { bodyLimit } from 'hono/body-limit' @@ -14,6 +11,10 @@ import { HttpStatus, createApexError } from './services/error.service' import { userStatsRouter } from './routes/user-stats.route' import { publicResourceRouter, resourceRouter } from './routes/resource.route' import { publicStatsResourceRouter, statsResourceRouter } from './routes/stats-resource.route' +import { collectionsRouter, getCollections } from './routes/collections.route' +import { signUpRouter, userRouter } from './routes/user.route' +import { uploaderRouter } from './routes/uploader.route' +import { collectionsStatsRouter, getCollectionsStats } from './routes/collection-stats.route' const app = new Hono() @@ -65,6 +66,13 @@ app .route('/resource', resourceRouter) .route('/statsResource', statsResourceRouter) +app.route('/getCollections', getCollections) +app.route('/get-collections', getCollections) +app.route('/get-collection-stats', getCollectionsStats) +app + .basePath('/api') + .route('/collection', collectionsRouter) + .route('/collection-stats', collectionsStatsRouter) export default app export type AppType = typeof app diff --git a/src/routes/client.route.ts b/src/routes/client.route.ts deleted file mode 100644 index 7682c33687e0e9d2e0dbc69240119b61dd382112..0000000000000000000000000000000000000000 --- a/src/routes/client.route.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { ClientService } from '@/services/client.service' -import Container from 'typedi' -import { honoWithJwt } from '..' -import { zValidator } from '@hono/zod-validator' -import { clientSchemas } from '@/db/schema/client.model' -import { HttpStatus, createApexError } from '@/services/error.service' - -const service = Container.get(ClientService) - -export const clientRouter = honoWithJwt() - .post( - '/create', - zValidator('json', clientSchemas.clientInputSchema), - async (c) => { - try { - const input = await c.req.valid('json') - - const client = clientSchemas.clientDtoSchema.parse( - await service.create(input) - ) - - return c.json({ client }) - } catch (e) { - return c.json( - createApexError({ - status: 'error', - message: 'could not create client', - code: HttpStatus.BAD_REQUEST, - path: c.req.routePath, - suggestion: 'check the input and try again', - }), - HttpStatus.BAD_REQUEST - ) - } - } - ) - .post( - '/update', - zValidator('json', clientSchemas.clientUpdateSchema), - async (c) => { - try { - const input = await c.req.valid('json') - - const client = clientSchemas.clientDtoSchema.parse( - await service.update(input) - ) - - return c.json({ client }) - } catch (e) { - console.log(e) - - return c.json( - createApexError({ - status: 'error', - message: 'could not update client', - code: HttpStatus.BAD_REQUEST, - path: c.req.routePath, - suggestion: 'check the input and try again', - }), - HttpStatus.BAD_REQUEST - ) - } - } - ) - .post('/delete/:id', async (c) => { - try { - const id = c.req.param('id') - - const client = clientSchemas.clientDtoSchema.parse( - await service.delete(id) - ) - - return c.json({ client }) - } catch (e) { - return c.json( - createApexError({ - status: 'error', - message: 'could not delete client', - code: HttpStatus.BAD_REQUEST, - path: c.req.routePath, - suggestion: 'check the input and try again', - }), - HttpStatus.BAD_REQUEST - ) - } - }) - .get('/:id', async (c) => { - try { - const id = c.req.param('id') - - const client = clientSchemas.clientDtoSchema.parse( - await service.find(id) - ) - - return c.json({ client }) - } catch (e) { - return c.json( - createApexError({ - status: 'error', - message: 'could not find client', - code: HttpStatus.NOT_FOUND, - path: c.req.routePath, - suggestion: 'are you sure this client exists?', - }), - HttpStatus.NOT_FOUND - ) - } - }) diff --git a/src/routes/collection-stats.route.ts b/src/routes/collection-stats.route.ts new file mode 100644 index 0000000000000000000000000000000000000000..69608b0a2419a25dd9732440583f92fd53c6d2cd --- /dev/null +++ b/src/routes/collection-stats.route.ts @@ -0,0 +1,229 @@ +import { CollectionStatsService } from "@/services/collection-stats.service"; +import Container from "typedi"; +import { honoWithJwt } from ".."; +import { zValidator } from "@hono/zod-validator"; +import { collectionStatsSchemas } from "@/db/schema/collection-stats.model"; +import { createApexError, HttpStatus } from "@/services/error.service"; +import { Hono } from "hono"; + +const service = Container.get(CollectionStatsService); + +export const collectionsStatsRouter = honoWithJwt() + .post( + '/create', + zValidator('json', collectionStatsSchemas.collectionStatsInputSchema), + async (c) => { + try { + const input = await c.req.valid('json') + + const collectionStats = collectionStatsSchemas.collectionStatsDtoSchema.parse( + await service.create(input) + ) + + return c.json({ collectionStats }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not create collection stats', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + .post( + '/update-views/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collectionStats = collectionStatsSchemas.collectionStatsDtoSchema.parse( + await service.updateViews(id) + ) + + return c.json({ collectionStats }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not update collection stats', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + .post( + '/update-downloads/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collectionStats = collectionStatsSchemas.collectionStatsDtoSchema.parse( + await service.updateDownloads(id) + ) + + return c.json({ collectionStats }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not update collection stats', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + .post( + '/update-likes/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collectionStats = collectionStatsSchemas.collectionStatsDtoSchema.parse( + await service.updateLikes(id) + ) + + return c.json({ collectionStats }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not update collection stats', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + .post( + '/update-shares/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collectionStats = collectionStatsSchemas.collectionStatsDtoSchema.parse( + await service.updateShares(id) + ) + + return c.json({ collectionStats }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not update collection stats', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + .post( + '/update-score/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collectionStats = collectionStatsSchemas.collectionStatsDtoSchema.parse( + await service.updateScore(id) + ) + + return c.json({ collectionStats }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not update collection stats', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + .post( + '/update-followers/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collectionStats = collectionStatsSchemas.collectionStatsDtoSchema.parse( + await service.updateFollows(id) + ) + + return c.json({ collectionStats }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not update collection stats', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + .post( + '/delete/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collectionStats = collectionStatsSchemas.collectionStatsDtoSchema.parse( + await service.delete(id) + ) + + return c.json({ collectionStats }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not delete collection stats', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + +export const getCollectionsStats = new Hono() + .get('/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collectionStats = collectionStatsSchemas.collectionStatsDtoSchema.parse( + await service.find(id) + ) + + return c.json({ collectionStats }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not find collection stats', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.NOT_FOUND + ) + } + }) diff --git a/src/routes/collections.route.ts b/src/routes/collections.route.ts new file mode 100644 index 0000000000000000000000000000000000000000..ada80e272a77230329f0665e9331f87f6f410c0e --- /dev/null +++ b/src/routes/collections.route.ts @@ -0,0 +1,181 @@ +import { CollectionsService } from "@/services/collections.service"; +import Container from "typedi"; +import { honoWithJwt } from ".."; +import { zValidator } from "@hono/zod-validator"; +import { collectionSchemas } from "@/db/schema/collections.model"; +import { createApexError, HttpStatus } from "@/services/error.service"; +import { Hono } from "hono"; +import { collectionStatsSchemas } from "@/db/schema/collection-stats.model"; +import { CollectionStatsService } from "@/services/collection-stats.service"; + +const service = Container.get(CollectionsService); +const serviceStats = Container.get(CollectionStatsService); + +export const collectionsRouter = honoWithJwt() + .post( + '/create', + zValidator('json', collectionSchemas.collectionInputSchema), + async (c) => { + try { + const input = await c.req.valid('json') + + const collection = collectionSchemas.collectionDtoSchema.parse( + await service.create(input) + ) + + const collectionStats = collectionStatsSchemas.collectionStatsDtoSchema.parse( + await serviceStats.create({ collectionId: collection.id }) + ) + + return c.json({ collection, collectionStats }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not create collection', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + .post ( + '/update', + zValidator('json', collectionSchemas.collectionUpdateSchema), + async (c) => { + try { + const input = await c.req.valid('json') + + const collection = collectionSchemas.collectionDtoSchema.parse( + await service.update(input) + ) + + return c.json({ collection }) + } catch (e) { + console.log(e) + + return c.json( + createApexError({ + status: 'error', + message: 'could not update collection', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + .post('/delete/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collection = collectionSchemas.collectionDtoSchema.parse( + await service.delete(id) + ) + + return c.json({ collection }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not delete collection', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + }) + .post('/delete-permanently/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collection = collectionSchemas.collectionDtoSchema.parse( + await service.deletePermanently(id) + ) + + return c.json({ collection }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not delete collection permanently', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + }) + .post('/restore/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collection = collectionSchemas.collectionDtoSchema.parse( + await service.restore(id) + ) + + return c.json({ collection }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not restore collection', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + }}) + + export const getCollections = new Hono () + .get('/:id', async (c) => { + try { + const id = +c.req.param('id') + + const collection = collectionSchemas.collectionDtoSchema.parse( + await service.find(id) + ) + + return c.json({ collection }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not find collection', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.NOT_FOUND + ) + } + }) + .get('/', async (c) => { + try { + const collections = collectionSchemas.collectionDtoSchema.array().parse( + await service.findMany() + ) + + return c.json({ collections }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not find collections', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.NOT_FOUND + ) + } + }) \ No newline at end of file diff --git a/src/routes/credit-card.route.ts b/src/routes/credit-card.route.ts deleted file mode 100644 index 71fdf123d5984acab64b0d57448ba5751bfb72f1..0000000000000000000000000000000000000000 --- a/src/routes/credit-card.route.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { CreditCardService } from '@/services/credit-card.service' -import Container from 'typedi' -import { honoWithJwt } from '..' -import { zValidator } from '@hono/zod-validator' -import { creditCardSchemas } from '@/db/schema/credit-card.model' -import { HttpStatus, createApexError } from '@/services/error.service' - -const service = Container.get(CreditCardService) - -export const creditCardRouter = honoWithJwt() - .post( - '/create', - zValidator('json', creditCardSchemas.creditCardInputSchema), - async (c) => { - try { - const input = await c.req.valid('json') - - const creditCard = - creditCardSchemas.creditCardDtoSchema.parse( - await service.create(input) - ) - - return c.json({ creditCard }) - } catch (e) { - return c.json( - createApexError({ - status: 'error', - message: 'could not create credit card', - code: HttpStatus.BAD_REQUEST, - path: c.req.routePath, - suggestion: 'check the input and try again', - }), - HttpStatus.BAD_REQUEST - ) - } - } - ) - .post( - '/update', - zValidator('json', creditCardSchemas.creditCardUpdateSchema), - async (c) => { - try { - const input = await c.req.valid('json') - - const creditCard = - creditCardSchemas.creditCardDtoSchema.parse( - await service.update(input) - ) - - return c.json({ creditCard }) - } catch (e) { - console.log(e) - - return c.json( - createApexError({ - status: 'error', - message: 'could not update credit card', - code: HttpStatus.BAD_REQUEST, - path: c.req.routePath, - suggestion: 'check the input and try again', - }), - HttpStatus.BAD_REQUEST - ) - } - } - ) - .post('/delete/:id', async (c) => { - try { - const id = c.req.param('id') - - const creditCard = creditCardSchemas.creditCardDtoSchema.parse( - await service.delete(id) - ) - - return c.json({ creditCard }) - } catch (e) { - return c.json( - createApexError({ - status: 'error', - message: 'could not delete credit card', - code: HttpStatus.BAD_REQUEST, - path: c.req.routePath, - suggestion: 'check the input and try again', - }), - HttpStatus.BAD_REQUEST - ) - } - }) - .get('/:id', async (c) => { - try { - const id = c.req.param('id') - - const creditCard = creditCardSchemas.creditCardDtoSchema.parse( - await service.find(id) - ) - - return c.json({ creditCard }) - } catch (e) { - return c.json( - createApexError({ - status: 'error', - message: 'could not find credit card', - code: HttpStatus.NOT_FOUND, - path: c.req.routePath, - suggestion: 'are you sure the credit card exists?', - }), - HttpStatus.NOT_FOUND - ) - } - }) diff --git a/src/routes/user.routes.ts b/src/routes/user.route.ts similarity index 85% rename from src/routes/user.routes.ts rename to src/routes/user.route.ts index b40e5eca7e25746f107912db8778c115a5037617..d7b9c50acab9ca5622d402061b60a9ffbda596fc 100644 --- a/src/routes/user.routes.ts +++ b/src/routes/user.route.ts @@ -6,11 +6,8 @@ import { zValidator } from '@hono/zod-validator' import { honoWithJwt } from '..' import { Hono } from 'hono' import { createApexError, HttpStatus } from '@/services/error.service' -import { userStatsSchemas } from '@/db/schema/user-stats.model' -import { UserStatsService } from '@/services/user-stats.service' const service = Container.get(UserService) -const userStatsService = Container.get(UserStatsService) export const signUpRouter = new Hono() .post('/', @@ -18,18 +15,12 @@ export const signUpRouter = new Hono() async (c) => { try { const input = await c.req.valid('json') + const user = userSchemas.userDtoSchema.parse( await service.create(input) ) - const user_stats_schema = { - user_id: user.id - } - const user_stats = userStatsSchemas.userStatsDtoSchema.parse( - await userStatsService.create(user_stats_schema) - ) - - return c.json({ user, user_stats }) + return c.json({ user }) } catch (e) { return c.text('could not create') } diff --git a/src/services/client.service.ts b/src/services/client.service.ts deleted file mode 100644 index 3622e7030ce4dd951b61ef66477e9c89b42e848c..0000000000000000000000000000000000000000 --- a/src/services/client.service.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { ClientRepo } from '@/db/repo/client.repo' -import type { - ClientInput, - ClientModel, - ClientUpdate, -} from '@/db/schema/client.model' -import { Inject, Service } from 'typedi' - -@Service() -export class ClientService { - @Inject() - private readonly repo: ClientRepo - - async create(client: ClientInput): Promise<ClientModel> { - return this.repo.create(client) - } - - async update(client: ClientUpdate): Promise<ClientModel> { - return this.repo.update(client) - } - - async delete(id: ClientModel['id']): Promise<ClientModel> { - return this.repo.delete(id) - } - - async find( - id: ClientModel['id'] - ): Promise<ClientModel | undefined> { - return this.repo.find(id) - } -} diff --git a/src/services/collection-stats.service.ts b/src/services/collection-stats.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..8b24328864b7ddbecfd6b0ecbfcc4f6b60413d82 --- /dev/null +++ b/src/services/collection-stats.service.ts @@ -0,0 +1,47 @@ +import { CollectionStatsRepo } from "@/db/repo/collection-stats.repo"; +import type { CollectionStatsInput, CollectionStatsModel, CollectionStatsUpdate } from "@/db/schema/collection-stats.model"; +import { Inject, Service } from "typedi"; + +@Service() +export class CollectionStatsService { + @Inject() + private readonly repo: CollectionStatsRepo + + async create(collectionStats: CollectionStatsInput): Promise<CollectionStatsModel> { + return this.repo.create(collectionStats) + } + + async updateViews(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + return this.repo.updateViews(id) + } + + async updateDownloads(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + return this.repo.updateDownloads(id) + } + + async updateLikes(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + return this.repo.updateLikes(id) + } + + async updateShares(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + return this.repo.updateShares(id) + } + + async updateScore(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + return this.repo.updateScore(id) + } + + async updateFollows(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + return this.repo.updateFollows(id) + } + + async delete(id: CollectionStatsModel['id']): Promise<CollectionStatsModel> { + return this.repo.delete(id) + } + + async find( + id: CollectionStatsModel['id'] + ): Promise<CollectionStatsModel | undefined> { + return this.repo.find(id) + } +} \ No newline at end of file diff --git a/src/services/collections.service.ts b/src/services/collections.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..99677488aea2c8954b400bc423353afa4e78fe18 --- /dev/null +++ b/src/services/collections.service.ts @@ -0,0 +1,43 @@ +import { CollectionRepo } from '@/db/repo/collections.repo' +import { Inject, Service } from 'typedi' +import type { + CollectionInput, + CollectionModel, + CollectionUpdate +} from '@/db/schema/collections.model' + +@Service() +export class CollectionsService { + @Inject() + private readonly repo: CollectionRepo + + async create(collection: CollectionInput): Promise<CollectionModel> { + return this.repo.create(collection) + } + + async update(collection: CollectionUpdate): Promise<CollectionModel> { + return this.repo.update(collection) + } + + async delete(id: CollectionModel['id']): Promise<CollectionModel> { + return this.repo.delete(id) + } + + async deletePermanently(id: CollectionModel['id']): Promise<CollectionModel> { + return this.repo.deletePermanently(id) + } + + async restore(id: CollectionModel['id']): Promise<CollectionModel> { + return this.repo.restore(id) + } + + async find( + id: CollectionModel['id'] + ): Promise<CollectionModel | undefined> { + return this.repo.find(id) + } + + async findMany(): Promise<CollectionModel[]> { + return this.repo.findMany() + } +} \ No newline at end of file diff --git a/src/services/credit-card.service.ts b/src/services/credit-card.service.ts deleted file mode 100644 index 62528755105a8197fc857c4ddfa40637b53b36f0..0000000000000000000000000000000000000000 --- a/src/services/credit-card.service.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { CreditCardRepo } from '@/db/repo/credit-card.repo' -import type { - CreditCardInput, - CreditCardModel, - CreditCardUpdate, -} from '@/db/schema/credit-card.model' -import { Inject, Service } from 'typedi' - -@Service() -export class CreditCardService { - @Inject() - private readonly repo: CreditCardRepo - - async create( - creditCard: CreditCardInput - ): Promise<CreditCardModel> { - return this.repo.create(creditCard) - } - - async update( - creditCard: CreditCardUpdate - ): Promise<CreditCardModel> { - return this.repo.update(creditCard) - } - - async delete(id: CreditCardModel['id']): Promise<CreditCardModel> { - return this.repo.delete(id) - } - - async find( - id: CreditCardModel['id'] - ): Promise<CreditCardModel | undefined> { - return this.repo.find(id) - } -}