Publishing is not an update
A post is published only once. We write that rule as a method and make status readOnly, so nothing else can change it, not even update.
fronds/blog/entities/Post.ts
+
import { entity, oneOf, primary, readOnly, text } from '@fougere/schema';2
3
export default class Post extends entity({4
id: primary(),5
title: text({ min: 1, max: 160 }),+
status: readOnly(oneOf('draft', 'published', { default: 'draft' })),d7
}) {}point at a lettered line, or tap it, to see what grows from it
A state changes through an operation, never through a field write.
Try it
$ curl -X POST localhost:4100/api/blog/posts/$ID/publish # twice 409 CONFLICT Already published
In the docsHandler