Fetch images
This commit is contained in:
parent
eba5f2d925
commit
449dfee86c
|
@ -130,6 +130,7 @@ declare namespace GQL {
|
||||||
|
|
||||||
interface IEventImages {
|
interface IEventImages {
|
||||||
__typename: 'EventImages';
|
__typename: 'EventImages';
|
||||||
|
event: ICalendarEvent | null;
|
||||||
thumb: IEventImage | null;
|
thumb: IEventImage | null;
|
||||||
cover: IEventImage | null;
|
cover: IEventImage | null;
|
||||||
poster: IEventImage | null;
|
poster: IEventImage | null;
|
||||||
|
|
|
@ -85,7 +85,7 @@ export class Event extends BaseEntity {
|
||||||
@OneToMany(type => EventImage, image => image.event, {
|
@OneToMany(type => EventImage, image => image.event, {
|
||||||
onDelete: 'CASCADE'
|
onDelete: 'CASCADE'
|
||||||
})
|
})
|
||||||
images: EventImage[]
|
images: Promise<EventImage[]>
|
||||||
|
|
||||||
@Column(type => EventLocation)
|
@Column(type => EventLocation)
|
||||||
location: EventLocation
|
location: EventLocation
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { getTags } from "./EventsService"
|
||||||
import { equals } from "ramda"
|
import { equals } from "ramda"
|
||||||
import { User } from "../Auth/User.entity"
|
import { User } from "../Auth/User.entity"
|
||||||
import { hasAnyRole } from "../Auth/authUtils"
|
import { hasAnyRole } from "../Auth/authUtils"
|
||||||
import { EventTag } from "../Calendar/EventTag.entity"
|
import { ImageType } from "../Image/EventImage.entity";
|
||||||
|
|
||||||
const resolvers: ResolverMap = {
|
const resolvers: ResolverMap = {
|
||||||
Query: {
|
Query: {
|
||||||
|
@ -53,9 +53,17 @@ const resolvers: ResolverMap = {
|
||||||
},
|
},
|
||||||
tags: async (event: Event) => {
|
tags: async (event: Event) => {
|
||||||
return event.tags
|
return event.tags
|
||||||
}
|
},
|
||||||
|
images: async (event: Event) => {
|
||||||
|
const allImages = await event.images
|
||||||
|
return {
|
||||||
|
thumb: allImages.filter(image => image.type === ImageType.Thumbnail)[0],
|
||||||
|
cover: allImages.filter(image => image.type === ImageType.Cover)[0],
|
||||||
|
poster: allImages.filter(image => image.type === ImageType.Poster)[0],
|
||||||
|
gallery: allImages.filter(image => image.type === ImageType.Gallery),
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
EventOccurrence: {
|
EventOccurrence: {
|
||||||
start: (eOcc: EventOccurrence) => {
|
start: (eOcc: EventOccurrence) => {
|
||||||
return eOcc.start
|
return eOcc.start
|
||||||
|
@ -105,7 +113,7 @@ const resolvers: ResolverMap = {
|
||||||
}
|
}
|
||||||
if (input.tagNames) {
|
if (input.tagNames) {
|
||||||
const tags = await getTags(input.tagNames)
|
const tags = await getTags(input.tagNames)
|
||||||
console.log('will set tags', tags)
|
console.log("will set tags", tags)
|
||||||
event.tags = Promise.resolve(tags)
|
event.tags = Promise.resolve(tags)
|
||||||
}
|
}
|
||||||
event.location = input.location
|
event.location = input.location
|
||||||
|
@ -124,7 +132,10 @@ const resolvers: ResolverMap = {
|
||||||
throw Error("not authenticated")
|
throw Error("not authenticated")
|
||||||
}
|
}
|
||||||
const event = await Event.findOne(id)
|
const event = await Event.findOne(id)
|
||||||
const isSuperUser = hasAnyRole(await context.user.roles, ['admin','embassador'])
|
const isSuperUser = hasAnyRole(await context.user.roles, [
|
||||||
|
"admin",
|
||||||
|
"embassador",
|
||||||
|
])
|
||||||
const isOwner = (await event.owner).id !== context.user.id
|
const isOwner = (await event.owner).id !== context.user.id
|
||||||
|
|
||||||
if (!(isSuperUser || isOwner)) {
|
if (!(isSuperUser || isOwner)) {
|
||||||
|
@ -162,7 +173,7 @@ const resolvers: ResolverMap = {
|
||||||
}
|
}
|
||||||
if (input.tagNames) {
|
if (input.tagNames) {
|
||||||
const tagsToSet = await getTags(input.tagNames)
|
const tagsToSet = await getTags(input.tagNames)
|
||||||
console.log('tagsToSet, ', tagsToSet)
|
console.log("tagsToSet, ", tagsToSet)
|
||||||
event.tags = Promise.resolve(tagsToSet)
|
event.tags = Promise.resolve(tagsToSet)
|
||||||
}
|
}
|
||||||
if (input.location) {
|
if (input.location) {
|
||||||
|
@ -173,7 +184,10 @@ const resolvers: ResolverMap = {
|
||||||
deleteEvent: async (_, id: string, context: Context): Promise<User> => {
|
deleteEvent: async (_, id: string, context: Context): Promise<User> => {
|
||||||
const event = await Event.findOne(id)
|
const event = await Event.findOne(id)
|
||||||
|
|
||||||
const isSuperUser = hasAnyRole(await context.user.roles, ['admin','embassador'])
|
const isSuperUser = hasAnyRole(await context.user.roles, [
|
||||||
|
"admin",
|
||||||
|
"embassador",
|
||||||
|
])
|
||||||
const isOwner = (await event.owner).id !== context.user.id
|
const isOwner = (await event.owner).id !== context.user.id
|
||||||
|
|
||||||
if (!(isSuperUser || isOwner)) {
|
if (!(isSuperUser || isOwner)) {
|
||||||
|
|
|
@ -48,6 +48,7 @@ type EventImage {
|
||||||
}
|
}
|
||||||
|
|
||||||
type EventImages {
|
type EventImages {
|
||||||
|
event: CalendarEvent
|
||||||
thumb: EventImage
|
thumb: EventImage
|
||||||
cover: EventImage
|
cover: EventImage
|
||||||
poster: EventImage
|
poster: EventImage
|
||||||
|
|
Loading…
Reference in New Issue