mirror of
https://github.com/aljazceru/landscape-template.git
synced 2025-12-18 14:54:23 +01:00
feat: add HostedImage relation in Category table + data migration to HostedImage
This commit is contained in:
@@ -122,7 +122,6 @@ export interface NexusGenObjects {
|
||||
workplan: string; // String!
|
||||
}
|
||||
Category: { // root type
|
||||
cover_image?: string | null; // String
|
||||
icon?: string | null; // String
|
||||
id: number; // Int!
|
||||
title: string; // String!
|
||||
|
||||
@@ -4,7 +4,8 @@ const {
|
||||
extendType,
|
||||
nonNull,
|
||||
} = require('nexus');
|
||||
const { prisma } = require('../../../prisma')
|
||||
const { prisma } = require('../../../prisma');
|
||||
const resolveImgObjectToUrl = require('../../../utils/resolveImageUrl');
|
||||
|
||||
|
||||
const Category = objectType({
|
||||
@@ -12,7 +13,17 @@ const Category = objectType({
|
||||
definition(t) {
|
||||
t.nonNull.int('id');
|
||||
t.nonNull.string('title');
|
||||
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.string('icon');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user