From 89121422a591ffa06541962daac994b4ead13af7 Mon Sep 17 00:00:00 2001 From: CarlosZoft Date: Wed, 3 Apr 2024 03:05:10 -0300 Subject: [PATCH] feat: added displayFeedImage field to donations --- bruno-collection/Register Donation.bru | 3 +- package.json | 4 +- .../[slug]/donations/index.post.ts | 25 ++-- .../migration.sql | 2 + server/db/schema.prisma | 1 + server/services/donationService.ts | 4 +- store/user.ts | 14 +- yarn.lock | 121 +++++++----------- 8 files changed, 81 insertions(+), 93 deletions(-) create mode 100644 server/db/migrations/20240403060107_add_display_feed_image/migration.sql diff --git a/bruno-collection/Register Donation.bru b/bruno-collection/Register Donation.bru index 203d000..dfeb1a5 100644 --- a/bruno-collection/Register Donation.bru +++ b/bruno-collection/Register Donation.bru @@ -23,6 +23,7 @@ body:json { "slug": "matricula", "value": "118053123" } - ] + ], + "displayFeedImage": false } } diff --git a/package.json b/package.json index 1140783..8cf1d14 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@nuxt/image": "^1.3.0", "@nuxtjs/google-fonts": "^3.1.0", "@pinia/nuxt": "^0.5.1", - "@prisma/client": "^5.9.1", + "@prisma/client": "5.12.0", "@types/jsonwebtoken": "^9.0.5", "dayjs": "^1.11.10", "element-plus": "^2.4.3", @@ -31,6 +31,6 @@ "schema": "server/db/schema.prisma" }, "dependencies": { - "prisma": "^5.9.1" + "prisma": "5.12.0" } } diff --git a/server/api/v1/competitions/[slug]/donations/index.post.ts b/server/api/v1/competitions/[slug]/donations/index.post.ts index 99fa927..798da38 100644 --- a/server/api/v1/competitions/[slug]/donations/index.post.ts +++ b/server/api/v1/competitions/[slug]/donations/index.post.ts @@ -4,34 +4,30 @@ import { registerDonation } from "~/server/services/donationService"; import { getPrettyFullName } from "~/utils/getPrettyFullName"; export default defineEventHandler(async (event) => { - const competitionSlug = String(getRouterParam(event, 'slug')); + const competitionSlug = String(getRouterParam(event, "slug")); const user = useHemocioneUserAuth(event); const competition = await getCompetitionBySlug(competitionSlug); if (!competition) { throw createError({ - "statusCode": 404, - "statusMessage": "Competition not found" + statusCode: 404, + statusMessage: "Competition not found", }); } const now = new Date(); - const isCompetitionInFuture = competition.start_at && competition.start_at > now; + const isCompetitionInFuture = + competition.start_at && competition.start_at > now; const isCompetitionInPast = competition.end_at && competition.end_at < now; if (isCompetitionInFuture || isCompetitionInPast) { throw createError({ - "statusCode": 400, - "statusMessage": "Bad Request - Competition is not active" + statusCode: 400, + statusMessage: "Bad Request - Competition is not active", }); } const body = await readBody(event); - const { - proof, - extraFields, - competitionTeamId, - } = body; - + const { proof, extraFields, competitionTeamId, displayFeedImage } = body; if (!competitionTeamId) { throw createError({ @@ -54,7 +50,8 @@ export default defineEventHandler(async (event) => { hemocioneID: user.id, extraFields, proof, - } + displayFeedImage, + }; const createdDonation = await registerDonation( competition.id, @@ -63,4 +60,4 @@ export default defineEventHandler(async (event) => { ); return createdDonation; -}); \ No newline at end of file +}); diff --git a/server/db/migrations/20240403060107_add_display_feed_image/migration.sql b/server/db/migrations/20240403060107_add_display_feed_image/migration.sql new file mode 100644 index 0000000..352911b --- /dev/null +++ b/server/db/migrations/20240403060107_add_display_feed_image/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "donations" ADD COLUMN "displayFeedImage" BOOLEAN DEFAULT false; diff --git a/server/db/schema.prisma b/server/db/schema.prisma index 8515916..6516e33 100644 --- a/server/db/schema.prisma +++ b/server/db/schema.prisma @@ -74,6 +74,7 @@ model donations { updatedAt DateTime @updatedAt competitions competitions @relation(fields: [competitionId], references: [id], onDelete: NoAction, onUpdate: NoAction) competitionTeams competitionTeams? @relation(fields: [competitionTeamId], references: [id], onDelete: NoAction, onUpdate: NoAction) + displayFeedImage Boolean? @default(false) @@unique([user_email, competitionId]) @@index([competitionId, hemocioneID], map: "donations_competitionId_hemocioneID") // HemocioneID is the unique identifier for the user in the competition. will be unique in the future, since there are donations with only emails in the database diff --git a/server/services/donationService.ts b/server/services/donationService.ts index 72b0818..0b3e5ad 100644 --- a/server/services/donationService.ts +++ b/server/services/donationService.ts @@ -9,9 +9,10 @@ export const registerDonation = async ( user_email: string, extraFields?: string proof?: string + displayFeedImage?: boolean } ) => { - const { user_name, user_email, extraFields, hemocioneID, proof } = payload; + const { user_name, user_email, extraFields, hemocioneID, proof, displayFeedImage } = payload; return await dbClient.$transaction(async (db) => { const createdDonation = await db.donations.create({ data: { @@ -22,6 +23,7 @@ export const registerDonation = async ( competitionId: competitionId, ...(extraFields ? { extraFields } : {}), ...(proof ? { proof } : {}), + ...(displayFeedImage ? { displayFeedImage } : {}), }, }); diff --git a/store/user.ts b/store/user.ts index fa0c4bc..d9e8adf 100644 --- a/store/user.ts +++ b/store/user.ts @@ -8,14 +8,24 @@ export const getUserDonation = async (competitionSlug: string, token: string) => }); } -export const registerDonation = async (competitionSlug: string, token: string, payload: { proof: string, extraFields: ExtraFieldsResponse, competitionTeamId: number }) => { - const { proof, extraFields, competitionTeamId } = payload; +export const registerDonation = async ( + competitionSlug: string, + token: string, + payload: { + proof: string, + extraFields: ExtraFieldsResponse, + competitionTeamId: number, + displayFeedImage?: boolean + } +) => { + const { proof, extraFields, competitionTeamId, displayFeedImage} = payload; return await $fetch(`/api/v1/competitions/${competitionSlug}/donations`, { method: "POST", body: { competitionTeamId, proof, extraFields, + displayFeedImage }, headers: { Authorization: `Bearer ${token}` diff --git a/yarn.lock b/yarn.lock index 68da13c..69820ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1675,46 +1675,46 @@ resolved "https://registry.yarnpkg.com/@sxzz/popperjs-es/-/popperjs-es-2.11.7.tgz#a7f69e3665d3da9b115f9e71671dae1b97e13671" integrity sha512-Ccy0NlLkzr0Ex2FKvh2X+OyERHXJ88XJ1MXtsI9y9fGexlaXaVTPzBCRBwIxFkORuOb+uBqeu+RqnpgYTEZRUQ== -"@prisma/client@^5.9.1": - version "5.9.1" - resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.9.1.tgz#d92bd2f7f006e0316cb4fda9d73f235965cf2c64" - integrity sha512-caSOnG4kxcSkhqC/2ShV7rEoWwd3XrftokxJqOCMVvia4NYV/TPtJlS9C2os3Igxw/Qyxumj9GBQzcStzECvtQ== - -"@prisma/debug@5.9.1": - version "5.9.1" - resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.9.1.tgz#906274e73d3267f88b69459199fa3c51cd9511a3" - integrity sha512-yAHFSFCg8KVoL0oRUno3m60GAjsUKYUDkQ+9BA2X2JfVR3kRVSJFc/GpQ2fSORi4pSHZR9orfM4UC9OVXIFFTA== - -"@prisma/engines-version@5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64": - version "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64" - resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64.tgz#54d2164f28d23e09d41cf9eb0bddbbe7f3aaa660" - integrity sha512-HFl7275yF0FWbdcNvcSRbbu9JCBSLMcurYwvWc8WGDnpu7APxQo2ONtZrUggU3WxLxUJ2uBX+0GOFIcJeVeOOQ== - -"@prisma/engines@5.9.1": - version "5.9.1" - resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.9.1.tgz#767539afc6f193a182d0495b30b027f61f279073" - integrity sha512-gkdXmjxQ5jktxWNdDA5aZZ6R8rH74JkoKq6LD5mACSvxd2vbqWeWIOV0Py5wFC8vofOYShbt6XUeCIUmrOzOnQ== - dependencies: - "@prisma/debug" "5.9.1" - "@prisma/engines-version" "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64" - "@prisma/fetch-engine" "5.9.1" - "@prisma/get-platform" "5.9.1" - -"@prisma/fetch-engine@5.9.1": - version "5.9.1" - resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.9.1.tgz#5d3b2c9af54a242e37b3f9561b59ab72f8e92818" - integrity sha512-l0goQOMcNVOJs1kAcwqpKq3ylvkD9F04Ioe1oJoCqmz05mw22bNAKKGWuDd3zTUoUZr97va0c/UfLNru+PDmNA== - dependencies: - "@prisma/debug" "5.9.1" - "@prisma/engines-version" "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64" - "@prisma/get-platform" "5.9.1" - -"@prisma/get-platform@5.9.1": - version "5.9.1" - resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.9.1.tgz#a66bb46ab4d30db786c84150ef074ab0aad4549e" - integrity sha512-6OQsNxTyhvG+T2Ksr8FPFpuPeL4r9u0JF0OZHUBI/Uy9SS43sPyAIutt4ZEAyqWQt104ERh70EZedkHZKsnNbg== - dependencies: - "@prisma/debug" "5.9.1" +"@prisma/client@5.12.0": + version "5.12.0" + resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.12.0.tgz#4d1fb68074307bf9445d06ad387139301aa4bcc4" + integrity sha512-bk/+KPpRm0+IzqFCtAxrj+/TNiHzulspnO+OkysaYY/atc/eX0Gx8V3tTLxbHKVX0LKD4Hi8KKCcSbU1U72n7Q== + +"@prisma/debug@5.12.0": + version "5.12.0" + resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.12.0.tgz#0d5d94f095ae2d7e59ce89d32ad7bc4112b155b0" + integrity sha512-wK3fQLxPLMqf5riT5ZIhl8NffPSzFUwtzFX5CH7z/oI9Swmo9UhQlUgZABIVgdXSJ5OAlmRcDZtDKaMApIl8sg== + +"@prisma/engines-version@5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab": + version "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab" + resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab.tgz#c78d099a3fe86d446db7442e64e56987e39e7f32" + integrity sha512-6yvO8s80Tym61aB4QNtYZfWVmE3pwqe807jEtzm8C5VDe7nw8O1FGX3TXUaXmWV0fQTIAfRbeL2Gwrndabp/0g== + +"@prisma/engines@5.12.0": + version "5.12.0" + resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.12.0.tgz#81a060d6eaf3da65c29bc7d81cd74fae72f13675" + integrity sha512-rFNRul9JGu0d3tf8etBgmDQ4NVoDwgGrRguvQOc8i+c6g7xPjRuu4aKzMMvHWUuccvRx5+fs1KMBxQ0x2THt+Q== + dependencies: + "@prisma/debug" "5.12.0" + "@prisma/engines-version" "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab" + "@prisma/fetch-engine" "5.12.0" + "@prisma/get-platform" "5.12.0" + +"@prisma/fetch-engine@5.12.0": + version "5.12.0" + resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.12.0.tgz#0418b29a0b473bb633871b43e3eb45c57a9157e5" + integrity sha512-qkHQbZ1hspvOwcImvqY4yj7+FUlw0+uP+6tu3g24V4ULHOXLLkvr5ZZc6vy26OF0hkbD3kcDJCeutFis3poKgg== + dependencies: + "@prisma/debug" "5.12.0" + "@prisma/engines-version" "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab" + "@prisma/get-platform" "5.12.0" + +"@prisma/get-platform@5.12.0": + version "5.12.0" + resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.12.0.tgz#72b3ca03181d6bb20596b40ed581d5e0b06512ec" + integrity sha512-81Ptv9YJnwTArEBPQ2Lvu58sZPxy4OixKxVVgysFan6A3bFP7q8gIg15WTjsRuH4WXh6B667EM9sqoMTNu0fLQ== + dependencies: + "@prisma/debug" "5.12.0" "@rollup/plugin-alias@^5.0.1": version "5.1.0" @@ -5995,12 +5995,12 @@ pretty-bytes@^6.1.1: resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-6.1.1.tgz#38cd6bb46f47afbf667c202cfc754bffd2016a3b" integrity sha512-mQUvGU6aUFQ+rNvTIAcZuWGRT9a6f6Yrg9bHs4ImKF+HZCEK+plBvnAZYSIQztknZF2qnzNtr6F8s0+IuptdlQ== -prisma@^5.9.1: - version "5.9.1" - resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.9.1.tgz#baa3dd635fbf71504980978f10f55ea11068f6aa" - integrity sha512-Hy/8KJZz0ELtkw4FnG9MS9rNWlXcJhf98Z2QMqi0QiVMoS8PzsBkpla0/Y5hTlob8F3HeECYphBjqmBxrluUrQ== +prisma@5.12.0: + version "5.12.0" + resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.12.0.tgz#b4194a549f5e0365233fb14f3fadef3bed057b5e" + integrity sha512-zxw4WSIvpsyNbpv8r7Fxgm7nwTFVmD6wbN6VuH13lClOceSANDOMl4jO3oxE6VzhjxmnEJqOGZjON2T2UpmLag== dependencies: - "@prisma/engines" "5.9.1" + "@prisma/engines" "5.12.0" proc-log@^3.0.0: version "3.0.0" @@ -6614,16 +6614,7 @@ streamx@^2.15.0: fast-fifo "^1.1.0" queue-tick "^1.0.1" -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -6655,14 +6646,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - -strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -7417,16 +7401,7 @@ wordwrapjs@^4.0.0: reduce-flatten "^2.0.0" typical "^5.2.0" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - -wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==