Last active
January 25, 2021 20:30
-
-
Save hdngr/32bfa129e716cd36956c613c48f4265f to your computer and use it in GitHub Desktop.
Asset updates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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