type-arango
Version:
ArangoDB Foxx decorators and utilities for TypeScript
28 lines (25 loc) • 722 B
text/typescript
import {Collection, Entities, Route, RouteArg} from '../../../../src' // type-arango
import {Book} from '../../shared'
({
of: Book,
relations: ['author'], // can be `true` to expose all relations
routes: ['LIST']
})
export class Books extends Entities {
/**
* Creates a new book
*/
.POST($ => ({
...$(Book)
}))
static CREATE({param,error}: RouteArg){
const { title } = param
const bookWithSameTitle = Books.find({filter:{title}})
if(bookWithSameTitle)
return error('bad request', 'Title is used by '+bookWithSameTitle.related('author').name)
return new Book({
title,
author: 1 // ie. session().uid
}).save()
}
}