Skip to content

Instantly share code, notes, and snippets.

@hdngr
Last active January 25, 2021 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdngr/32bfa129e716cd36956c613c48f4265f to your computer and use it in GitHub Desktop.
Save hdngr/32bfa129e716cd36956c613c48f4265f to your computer and use it in GitHub Desktop.
Asset updates
//and a stab at the type file Folder.ts:
import { objectType, extendType, arg } from 'nexus'
import { isLuminaAdmin } from '../auth'
export const Folder = objectType({
name: 'Folder',
definition(t) {
t.model.id()
t.model.name()
t.model.parent()
t.model.children()
t.model.assets()
t.model.customer()
t.model.createdAt()
t.model.updatedAt()
},
})
export const FolderQueries = extendType({
type: 'Query',
definition(t) {
t.crud.folder({
authorize: (_root, _args, ctx, _info) => {
return isLuminaAdmin(ctx)
},
})
t.crud.folders({
authorize: (_root, _args, ctx, _info) => {
return isLuminaAdmin(ctx)
},
ordering: true,
pagination: true,
filtering: true,
})
},
})
// and add the following to definition(t) in Asset.ts:
t.model.url()
t.model.folder()
t.model.name()
// schema.prisma
model Asset {
createdAt DateTime @default(now())
id Int @id @default(autoincrement())
publicId String @unique
url String
name String?
folderId Int
folder Folder @relation(fields: [folderId], references: [id])
updatedAt DateTime @updatedAt
}
model Folder {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
id Int @id @default(autoincrement())
name String?
parentId Int?
customerTenant String?
parent Folder? @relation(name: "FolderRelationship", fields: [parentId], references: [id])
children Folder[] @relation(name: "FolderRelationship")
assets Asset[]
customer Customer? @relation(fields: [customerTenant], references: [tenant])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment