From 764c6b662281e1daae22622b4e51e627dfb7ea47 Mon Sep 17 00:00:00 2001 From: MTG2000 Date: Fri, 9 Sep 2022 07:50:36 +0300 Subject: [PATCH] feat: add createdAt to userKeys, tour participations --- api/functions/graphql/types/users.js | 14 +++++++++++--- .../migration.sql | 5 +++++ prisma/schema.prisma | 6 ++++-- 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 prisma/migrations/20220909043627_add_created_at_to_keys_and_participations/migration.sql diff --git a/api/functions/graphql/types/users.js b/api/functions/graphql/types/users.js index 7bdb310..b1f6cf8 100644 --- a/api/functions/graphql/types/users.js +++ b/api/functions/graphql/types/users.js @@ -171,9 +171,16 @@ const MyProfile = objectType({ t.nonNull.list.nonNull.field('walletsKeys', { type: "WalletKey", - resolve: async (parent, _, context) => { - const userKeys = await prisma.user.findUnique({ where: { id: parent.id } }).userKeys(); - return userKeys.map(k => ({ ...k, is_current: k.key === context.userPubKey })) + resolve: (parent, _, context) => { + return prisma.userKey.findMany({ + where: { + user_id: parent.id, + }, + orderBy: { + createdAt: "asc" + } + }) + .then(keys => keys.map(k => ({ ...k, is_current: k.key === context.userPubKey }))) } }); } @@ -283,6 +290,7 @@ const WalletKey = objectType({ definition(t) { t.nonNull.string('key'); t.nonNull.string('name'); + t.nonNull.date('createdAt'); t.nonNull.boolean('is_current') } }) diff --git a/prisma/migrations/20220909043627_add_created_at_to_keys_and_participations/migration.sql b/prisma/migrations/20220909043627_add_created_at_to_keys_and_participations/migration.sql new file mode 100644 index 0000000..4bb777b --- /dev/null +++ b/prisma/migrations/20220909043627_add_created_at_to_keys_and_participations/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "TournamentParticipant" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "UserKey" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 974fc53..1f3c9a7 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -72,8 +72,9 @@ model User { } model UserKey { - key String @id - name String @default("My new wallet key") + key String @id + name String @default("My new wallet key") + createdAt DateTime @default(now()) user User? @relation(fields: [user_id], references: [id]) user_id Int? @@ -349,6 +350,7 @@ model TournamentParticipant { tournament_id Int user User @relation(fields: [user_id], references: [id]) user_id Int + createdAt DateTime @default(now()) email String hacking_status Int