mirror of
https://github.com/aljazceru/landscape-template.git
synced 2026-01-31 12:14:30 +01:00
feat: add HostedImage relation in award, Hackaton, Story and User tables + data migration to HostedImage
This commit is contained in:
@@ -104,7 +104,6 @@ export interface NexusGenObjects {
|
||||
applicants_count: number; // Int!
|
||||
applications: NexusGenRootTypes['BountyApplication'][]; // [BountyApplication!]!
|
||||
body: string; // String!
|
||||
cover_image?: string | null; // String
|
||||
createdAt: NexusGenScalars['Date']; // Date!
|
||||
deadline: string; // String!
|
||||
excerpt: string; // String!
|
||||
@@ -146,7 +145,6 @@ export interface NexusGenObjects {
|
||||
title: string; // String!
|
||||
}
|
||||
Hackathon: { // root type
|
||||
cover_image: string; // String!
|
||||
description: string; // String!
|
||||
end_date: NexusGenScalars['Date']; // Date!
|
||||
id: number; // Int!
|
||||
@@ -173,7 +171,6 @@ export interface NexusGenObjects {
|
||||
}
|
||||
Mutation: {};
|
||||
MyProfile: { // root type
|
||||
avatar: string; // String!
|
||||
bio?: string | null; // String
|
||||
email?: string | null; // String
|
||||
github?: string | null; // String
|
||||
@@ -220,7 +217,6 @@ export interface NexusGenObjects {
|
||||
}
|
||||
Story: { // root type
|
||||
body: string; // String!
|
||||
cover_image?: string | null; // String
|
||||
createdAt: NexusGenScalars['Date']; // Date!
|
||||
excerpt: string; // String!
|
||||
id: number; // Int!
|
||||
@@ -237,7 +233,6 @@ export interface NexusGenObjects {
|
||||
title: string; // String!
|
||||
}
|
||||
Tournament: { // root type
|
||||
cover_image: string; // String!
|
||||
description: string; // String!
|
||||
end_date: NexusGenScalars['Date']; // Date!
|
||||
id: number; // Int!
|
||||
@@ -247,7 +242,6 @@ export interface NexusGenObjects {
|
||||
website: string; // String!
|
||||
}
|
||||
User: { // root type
|
||||
avatar: string; // String!
|
||||
bio?: string | null; // String
|
||||
email?: string | null; // String
|
||||
github?: string | null; // String
|
||||
|
||||
@@ -6,6 +6,7 @@ const {
|
||||
nonNull,
|
||||
} = require('nexus');
|
||||
const { prisma } = require('../../../prisma');
|
||||
const resolveImgObjectToUrl = require('../../../utils/resolveImageUrl');
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +16,17 @@ const Hackathon = objectType({
|
||||
t.nonNull.int('id');
|
||||
t.nonNull.string('title');
|
||||
t.nonNull.string('description');
|
||||
t.nonNull.string('cover_image');
|
||||
t.nonNull.string('cover_image', {
|
||||
async resolve(parent) {
|
||||
const imgObject = await prisma.hostedImage.findUnique({
|
||||
where: {
|
||||
id: parent.cover_image_id
|
||||
}
|
||||
});
|
||||
|
||||
return resolveImgObjectToUrl(imgObject);
|
||||
}
|
||||
});
|
||||
t.nonNull.date('start_date');
|
||||
t.nonNull.date('end_date');
|
||||
t.nonNull.string('location');
|
||||
|
||||
@@ -15,6 +15,7 @@ const { prisma } = require('../../../prisma');
|
||||
const { getUserByPubKey } = require('../../../auth/utils/helperFuncs');
|
||||
const { ApolloError } = require('apollo-server-lambda');
|
||||
const { marked } = require('marked');
|
||||
const resolveImgObjectToUrl = require('../../../utils/resolveImageUrl');
|
||||
const { ImageInput } = require('./misc');
|
||||
|
||||
|
||||
@@ -72,7 +73,17 @@ const Story = objectType({
|
||||
t.nonNull.string('type', {
|
||||
resolve: () => t.typeName
|
||||
});
|
||||
t.string('cover_image');
|
||||
t.string('cover_image', {
|
||||
async resolve(parent) {
|
||||
const imgObject = await prisma.hostedImage.findUnique({
|
||||
where: {
|
||||
id: parent.cover_image_id
|
||||
}
|
||||
});
|
||||
|
||||
return resolveImgObjectToUrl(imgObject);
|
||||
}
|
||||
});
|
||||
t.nonNull.list.nonNull.field('comments', {
|
||||
type: "PostComment",
|
||||
resolve: (parent) => []
|
||||
@@ -140,7 +151,17 @@ const Bounty = objectType({
|
||||
t.nonNull.string('type', {
|
||||
resolve: () => 'Bounty'
|
||||
});
|
||||
t.string('cover_image');
|
||||
t.string('cover_image', {
|
||||
async resolve(parent) {
|
||||
const imgObject = await prisma.hostedImage.findUnique({
|
||||
where: {
|
||||
id: parent.cover_image_id
|
||||
}
|
||||
});
|
||||
|
||||
return resolveImgObjectToUrl(imgObject);
|
||||
}
|
||||
});
|
||||
t.nonNull.string('deadline');
|
||||
t.nonNull.int('reward_amount');
|
||||
t.nonNull.int('applicants_count');
|
||||
|
||||
@@ -16,7 +16,17 @@ const Tournament = objectType({
|
||||
t.nonNull.string('title');
|
||||
t.nonNull.string('description');
|
||||
t.nonNull.string('thumbnail_image');
|
||||
t.nonNull.string('cover_image');
|
||||
t.nonNull.string('cover_image', {
|
||||
async resolve(parent) {
|
||||
const imgObject = await prisma.hostedImage.findUnique({
|
||||
where: {
|
||||
id: parent.cover_image_id
|
||||
}
|
||||
});
|
||||
|
||||
return resolveImgObjectToUrl(imgObject);
|
||||
}
|
||||
});
|
||||
t.nonNull.date('start_date');
|
||||
t.nonNull.date('end_date');
|
||||
t.nonNull.string('website');
|
||||
|
||||
@@ -5,6 +5,7 @@ const { getUserByPubKey } = require("../../../auth/utils/helperFuncs");
|
||||
const { removeNulls } = require("./helpers");
|
||||
const { ImageInput } = require('./misc');
|
||||
const { Tournament } = require('./tournaments');
|
||||
const resolveImgObjectToUrl = require('../../../utils/resolveImageUrl');
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +15,17 @@ const BaseUser = interfaceType({
|
||||
definition(t) {
|
||||
t.nonNull.int('id');
|
||||
t.nonNull.string('name');
|
||||
t.nonNull.string('avatar');
|
||||
t.nonNull.string('avatar', {
|
||||
async resolve(parent) {
|
||||
const imgObject = await prisma.hostedImage.findUnique({
|
||||
where: {
|
||||
id: parent.avatar_id
|
||||
}
|
||||
});
|
||||
|
||||
return resolveImgObjectToUrl(imgObject);
|
||||
}
|
||||
});
|
||||
t.nonNull.date('join_date');
|
||||
t.string('role');
|
||||
t.string('email')
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Project" ADD COLUMN "cover_image_id" INTEGER,
|
||||
ADD COLUMN "screenshots_ids" INTEGER[],
|
||||
ADD COLUMN "thumbnail_image_id" INTEGER;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Project" ADD CONSTRAINT "Project_thumbnail_image_id_fkey" FOREIGN KEY ("thumbnail_image_id") REFERENCES "HostedImage"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Project" ADD CONSTRAINT "Project_cover_image_id_fkey" FOREIGN KEY ("cover_image_id") REFERENCES "HostedImage"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Category" ADD COLUMN "cover_image_id" INTEGER;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Category" ADD CONSTRAINT "Category_cover_image_id_fkey" FOREIGN KEY ("cover_image_id") REFERENCES "HostedImage"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,40 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Award" ADD COLUMN "image_id" INTEGER;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Category" ADD COLUMN "cover_image_id" INTEGER;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Hackathon" ADD COLUMN "cover_image_id" INTEGER;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Project" ADD COLUMN "cover_image_id" INTEGER,
|
||||
ADD COLUMN "screenshots_ids" INTEGER[],
|
||||
ADD COLUMN "thumbnail_image_id" INTEGER;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Story" ADD COLUMN "cover_image_id" INTEGER;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "User" ADD COLUMN "avatar_id" INTEGER;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "User" ADD CONSTRAINT "User_avatar_id_fkey" FOREIGN KEY ("avatar_id") REFERENCES "HostedImage"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Category" ADD CONSTRAINT "Category_cover_image_id_fkey" FOREIGN KEY ("cover_image_id") REFERENCES "HostedImage"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Project" ADD CONSTRAINT "Project_thumbnail_image_id_fkey" FOREIGN KEY ("thumbnail_image_id") REFERENCES "HostedImage"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Project" ADD CONSTRAINT "Project_cover_image_id_fkey" FOREIGN KEY ("cover_image_id") REFERENCES "HostedImage"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Award" ADD CONSTRAINT "Award_image_id_fkey" FOREIGN KEY ("image_id") REFERENCES "HostedImage"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Story" ADD CONSTRAINT "Story_cover_image_id_fkey" FOREIGN KEY ("cover_image_id") REFERENCES "HostedImage"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Hackathon" ADD CONSTRAINT "Hackathon_cover_image_id_fkey" FOREIGN KEY ("cover_image_id") REFERENCES "HostedImage"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -40,11 +40,13 @@ model Vote {
|
||||
// -----------------
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
pubKey String? @unique
|
||||
name String?
|
||||
avatar String?
|
||||
role String @default("user")
|
||||
id Int @id @default(autoincrement())
|
||||
pubKey String? @unique
|
||||
name String?
|
||||
avatar String?
|
||||
avatar_id Int?
|
||||
avatar_rel HostedImage? @relation("UserAvatar", fields: [avatar_id], references: [id])
|
||||
role String @default("user")
|
||||
|
||||
email String?
|
||||
jobTitle String?
|
||||
@@ -162,10 +164,12 @@ model ProjectRecruitRoles {
|
||||
}
|
||||
|
||||
model Award {
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
image String
|
||||
url String
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
image String
|
||||
image_id Int?
|
||||
image_rel HostedImage? @relation("AwardImage", fields: [image_id], references: [id])
|
||||
url String
|
||||
|
||||
project Project @relation(fields: [project_id], references: [id])
|
||||
project_id Int
|
||||
@@ -176,15 +180,17 @@ model Award {
|
||||
// -----------------
|
||||
|
||||
model Story {
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
body String
|
||||
excerpt String
|
||||
cover_image String?
|
||||
votes_count Int @default(0)
|
||||
is_published Boolean @default(true)
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
body String
|
||||
excerpt String
|
||||
cover_image String?
|
||||
cover_image_id Int?
|
||||
cover_image_rel HostedImage? @relation("StoryCoverImage", fields: [cover_image_id], references: [id])
|
||||
votes_count Int @default(0)
|
||||
is_published Boolean @default(true)
|
||||
|
||||
tags Tag[]
|
||||
|
||||
@@ -237,15 +243,17 @@ model PostComment {
|
||||
// Hackathons
|
||||
// -----------------
|
||||
model Hackathon {
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
start_date DateTime @db.Date
|
||||
end_date DateTime @db.Date
|
||||
cover_image String
|
||||
description String
|
||||
location String
|
||||
website String
|
||||
votes_count Int @default(0)
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
start_date DateTime @db.Date
|
||||
end_date DateTime @db.Date
|
||||
cover_image String
|
||||
cover_image_id Int?
|
||||
cover_image_rel HostedImage? @relation("HackathonCoverImage", fields: [cover_image_id], references: [id])
|
||||
description String
|
||||
location String
|
||||
website String
|
||||
votes_count Int @default(0)
|
||||
|
||||
tags Tag[]
|
||||
}
|
||||
@@ -287,9 +295,13 @@ model HostedImage {
|
||||
createdAt DateTime @default(now())
|
||||
is_used Boolean @default(false)
|
||||
|
||||
ProjectThumbnail Project[] @relation("ProjectThumbnail")
|
||||
ProjectCoverImage Project[] @relation("ProjectCoverImage")
|
||||
CategoryCoverImage Category[] @relation("CategoryCoverImage")
|
||||
ProjectThumbnail Project[] @relation("ProjectThumbnail")
|
||||
ProjectCoverImage Project[] @relation("ProjectCoverImage")
|
||||
CategoryCoverImage Category[] @relation("CategoryCoverImage")
|
||||
AwardImage Award[] @relation("AwardImage")
|
||||
HackathonCoverImage Hackathon[] @relation("HackathonCoverImage")
|
||||
StoryCoverImage Story[] @relation("StoryCoverImage")
|
||||
User User[] @relation("UserAvatar")
|
||||
}
|
||||
|
||||
// -----------------
|
||||
|
||||
@@ -136,6 +136,78 @@ async function migrateOldImages() {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Award
|
||||
**/
|
||||
const awards = await prisma.award.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
image: true,
|
||||
}
|
||||
})
|
||||
for (const award of awards) {
|
||||
if (award.image) {
|
||||
let hostedImageId = await _insertInHostedImage(award.image)
|
||||
await _updateObjectWithHostedImageId(prisma.award, award.id, {
|
||||
image_id: hostedImageId,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hackaton
|
||||
**/
|
||||
const hackatons = await prisma.hackathon.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
cover_image: true,
|
||||
}
|
||||
})
|
||||
for (const hackaton of hackatons) {
|
||||
if (hackaton.cover_image) {
|
||||
let hostedImageId = await _insertInHostedImage(hackaton.cover_image)
|
||||
await _updateObjectWithHostedImageId(prisma.hackathon, hackaton.id, {
|
||||
cover_image_id: hostedImageId,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Story
|
||||
**/
|
||||
const stories = await prisma.story.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
cover_image: true,
|
||||
}
|
||||
})
|
||||
for (const story of stories) {
|
||||
if (story.cover_image) {
|
||||
let hostedImageId = await _insertInHostedImage(story.cover_image)
|
||||
await _updateObjectWithHostedImageId(prisma.story, story.id, {
|
||||
cover_image_id: hostedImageId,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User
|
||||
**/
|
||||
const users = await prisma.user.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
avatar: true,
|
||||
}
|
||||
})
|
||||
for (const user of users) {
|
||||
if (user.avatar) {
|
||||
let hostedImageId = await _insertInHostedImage(user.avatar)
|
||||
await _updateObjectWithHostedImageId(prisma.user, user.id, {
|
||||
avatar_id: hostedImageId,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function _insertInHostedImage(url){
|
||||
|
||||
Reference in New Issue
Block a user