mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
using 201 for created entities in etapi
This commit is contained in:
parent
ce046b2e20
commit
2248d98cc7
BIN
db/demo.zip
BIN
db/demo.zip
Binary file not shown.
@ -19,20 +19,20 @@ function register(router) {
|
|||||||
'value': [v.notNull, v.isString],
|
'value': [v.notNull, v.isString],
|
||||||
'isInheritable': [v.notNull, v.isBoolean]
|
'isInheritable': [v.notNull, v.isBoolean]
|
||||||
};
|
};
|
||||||
|
|
||||||
eu.route(router, 'post' ,'/etapi/attributes', (req, res, next) => {
|
eu.route(router, 'post' ,'/etapi/attributes', (req, res, next) => {
|
||||||
if (req.body.type === 'relation') {
|
if (req.body.type === 'relation') {
|
||||||
eu.getAndCheckNote(req.body.value);
|
eu.getAndCheckNote(req.body.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const params = {};
|
const params = {};
|
||||||
|
|
||||||
eu.validateAndPatch(params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_ATTRIBUTE);
|
eu.validateAndPatch(params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_ATTRIBUTE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const attr = attributeService.createAttribute(params);
|
const attr = attributeService.createAttribute(params);
|
||||||
|
|
||||||
res.json(mappers.mapAttributeToPojo(attr));
|
res.status(201).json(mappers.mapAttributeToPojo(attr));
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
throw new eu.EtapiError(500, eu.GENERIC_CODE, e.message);
|
throw new eu.EtapiError(500, eu.GENERIC_CODE, e.message);
|
||||||
@ -49,9 +49,9 @@ function register(router) {
|
|||||||
if (attribute.type === 'relation') {
|
if (attribute.type === 'relation') {
|
||||||
eu.getAndCheckNote(req.body.value);
|
eu.getAndCheckNote(req.body.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
eu.validateAndPatch(attribute, req.body, ALLOWED_PROPERTIES_FOR_PATCH);
|
eu.validateAndPatch(attribute, req.body, ALLOWED_PROPERTIES_FOR_PATCH);
|
||||||
|
|
||||||
attribute.save();
|
attribute.save();
|
||||||
|
|
||||||
res.json(mappers.mapAttributeToPojo(attribute));
|
res.json(mappers.mapAttributeToPojo(attribute));
|
||||||
|
@ -12,8 +12,8 @@ function register(router) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {authToken} = etapiTokenService.createToken(tokenName || "ETAPI login");
|
const {authToken} = etapiTokenService.createToken(tokenName || "ETAPI login");
|
||||||
|
|
||||||
res.json({
|
res.status(201).json({
|
||||||
authToken
|
authToken
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -26,18 +26,18 @@ function register(router) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const etapiToken = becca.getEtapiToken(parsed.etapiTokenId);
|
const etapiToken = becca.getEtapiToken(parsed.etapiTokenId);
|
||||||
|
|
||||||
if (!etapiToken) {
|
if (!etapiToken) {
|
||||||
// shouldn't happen since this already passed auth validation
|
// shouldn't happen since this already passed auth validation
|
||||||
throw new Error(`Cannot find the token ${parsed.etapiTokenId}.`);
|
throw new Error(`Cannot find the token ${parsed.etapiTokenId}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
etapiToken.markAsDeletedSimple();
|
etapiToken.markAsDeletedSimple();
|
||||||
|
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
register
|
register
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,10 @@ function register(router) {
|
|||||||
'prefix': [v.isString],
|
'prefix': [v.isString],
|
||||||
'isExpanded': [v.notNull, v.isBoolean]
|
'isExpanded': [v.notNull, v.isBoolean]
|
||||||
};
|
};
|
||||||
|
|
||||||
eu.route(router, 'post' ,'/etapi/branches', (req, res, next) => {
|
eu.route(router, 'post' ,'/etapi/branches', (req, res, next) => {
|
||||||
const params = {};
|
const params = {};
|
||||||
|
|
||||||
eu.validateAndPatch(params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_BRANCH);
|
eu.validateAndPatch(params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_BRANCH);
|
||||||
|
|
||||||
const existing = becca.getBranchFromChildAndParent(params.noteId, params.parentNoteId);
|
const existing = becca.getBranchFromChildAndParent(params.noteId, params.parentNoteId);
|
||||||
@ -33,15 +33,16 @@ function register(router) {
|
|||||||
if (existing) {
|
if (existing) {
|
||||||
existing.notePosition = params.notePosition;
|
existing.notePosition = params.notePosition;
|
||||||
existing.prefix = params.prefix;
|
existing.prefix = params.prefix;
|
||||||
|
existing.isExpanded = params.isExpanded;
|
||||||
existing.save();
|
existing.save();
|
||||||
|
|
||||||
return res.json(mappers.mapBranchToPojo(existing));
|
return res.status(200).json(mappers.mapBranchToPojo(existing));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const branch = new Branch(params).save();
|
const branch = new Branch(params).save();
|
||||||
|
|
||||||
res.json(mappers.mapBranchToPojo(branch));
|
res.status(201).json(mappers.mapBranchToPojo(branch));
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
throw new eu.EtapiError(400, eu.GENERIC_CODE, e.message);
|
throw new eu.EtapiError(400, eu.GENERIC_CODE, e.message);
|
||||||
|
@ -27,7 +27,7 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/CreateNoteDef'
|
$ref: '#/components/schemas/CreateNoteDef'
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'201':
|
||||||
description: note created
|
description: note created
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
@ -56,7 +56,7 @@ paths:
|
|||||||
description: search query string as described in https://github.com/zadam/trilium/wiki/Search
|
description: search query string as described in https://github.com/zadam/trilium/wiki/Search
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
examples:
|
examples:
|
||||||
fulltext:
|
fulltext:
|
||||||
summary: Fulltext search for keywords (not exact match)
|
summary: Fulltext search for keywords (not exact match)
|
||||||
value: 'towers tolkien'
|
value: 'towers tolkien'
|
||||||
@ -205,7 +205,7 @@ paths:
|
|||||||
$ref: '#/components/schemas/Note'
|
$ref: '#/components/schemas/Note'
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: update note
|
description: note updated
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
@ -252,7 +252,10 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Error'
|
$ref: '#/components/schemas/Error'
|
||||||
post:
|
post:
|
||||||
description: create a branch (clone a note to a different location in the tree)
|
description: >
|
||||||
|
Create a branch (clone a note to a different location in the tree).
|
||||||
|
In case there is a branch between parent note and child note already,
|
||||||
|
then this will update the existing branch with prefix, notePosition and isExpanded.
|
||||||
operationId: postBranch
|
operationId: postBranch
|
||||||
requestBody:
|
requestBody:
|
||||||
required: true
|
required: true
|
||||||
@ -262,11 +265,17 @@ paths:
|
|||||||
$ref: '#/components/schemas/Branch'
|
$ref: '#/components/schemas/Branch'
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: update branch
|
description: branch updated (branch between parent note and child note already existed)
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Note'
|
$ref: '#/components/schemas/Branch'
|
||||||
|
'201':
|
||||||
|
description: branch created
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Branch'
|
||||||
default:
|
default:
|
||||||
description: unexpected error
|
description: unexpected error
|
||||||
content:
|
content:
|
||||||
@ -284,11 +293,11 @@ paths:
|
|||||||
$ref: '#/components/schemas/Branch'
|
$ref: '#/components/schemas/Branch'
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: update branch
|
description: branch updated
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Note'
|
$ref: '#/components/schemas/Branch'
|
||||||
default:
|
default:
|
||||||
description: unexpected error
|
description: unexpected error
|
||||||
content:
|
content:
|
||||||
@ -342,8 +351,8 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Attribute'
|
$ref: '#/components/schemas/Attribute'
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'201':
|
||||||
description: update attribute
|
description: attribute created
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
@ -365,7 +374,7 @@ paths:
|
|||||||
$ref: '#/components/schemas/Attribute'
|
$ref: '#/components/schemas/Attribute'
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: update attribute
|
description: attribute updated
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
@ -421,7 +430,7 @@ paths:
|
|||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
format: date
|
format: date
|
||||||
example: 2022-02-22
|
example: 2022-02-22
|
||||||
responses:
|
responses:
|
||||||
@ -547,17 +556,17 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
properties:
|
properties:
|
||||||
password:
|
password:
|
||||||
type: string
|
type: string
|
||||||
description: user's password used to e.g. login to Trilium server and/or protect notes
|
description: user's password used to e.g. login to Trilium server and/or protect notes
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'201':
|
||||||
description: auth token
|
description: auth token
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
properties:
|
properties:
|
||||||
authToken:
|
authToken:
|
||||||
type: string
|
type: string
|
||||||
example: Bc4bFn0Ffiok_4NpbVCDnFz7B2WU+pdhW8B5Ne3DiR5wXrEyqdjgRIsk=
|
example: Bc4bFn0Ffiok_4NpbVCDnFz7B2WU+pdhW8B5Ne3DiR5wXrEyqdjgRIsk=
|
||||||
@ -602,7 +611,7 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
type:
|
type:
|
||||||
type: string
|
type: string
|
||||||
enum:
|
enum:
|
||||||
- text
|
- text
|
||||||
- code
|
- code
|
||||||
- file
|
- file
|
||||||
|
@ -15,21 +15,21 @@ function register(router) {
|
|||||||
if (!search?.trim()) {
|
if (!search?.trim()) {
|
||||||
throw new eu.EtapiError(400, 'SEARCH_QUERY_PARAM_MANDATORY', "'search' query parameter is mandatory");
|
throw new eu.EtapiError(400, 'SEARCH_QUERY_PARAM_MANDATORY', "'search' query parameter is mandatory");
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchParams = parseSearchParams(req);
|
const searchParams = parseSearchParams(req);
|
||||||
const searchContext = new SearchContext(searchParams);
|
const searchContext = new SearchContext(searchParams);
|
||||||
|
|
||||||
const searchResults = searchService.findResultsWithQuery(search, searchContext);
|
const searchResults = searchService.findResultsWithQuery(search, searchContext);
|
||||||
const foundNotes = searchResults.map(sr => becca.notes[sr.noteId]);
|
const foundNotes = searchResults.map(sr => becca.notes[sr.noteId]);
|
||||||
|
|
||||||
const resp = {
|
const resp = {
|
||||||
results: foundNotes.map(note => mappers.mapNoteToPojo(note))
|
results: foundNotes.map(note => mappers.mapNoteToPojo(note))
|
||||||
};
|
};
|
||||||
|
|
||||||
if (searchContext.debugInfo) {
|
if (searchContext.debugInfo) {
|
||||||
resp.debugInfo = searchContext.debugInfo;
|
resp.debugInfo = searchContext.debugInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json(resp);
|
res.json(resp);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -51,16 +51,16 @@ function register(router) {
|
|||||||
'noteId': [v.notNull, v.isValidEntityId],
|
'noteId': [v.notNull, v.isValidEntityId],
|
||||||
'branchId': [v.notNull, v.isValidEntityId],
|
'branchId': [v.notNull, v.isValidEntityId],
|
||||||
};
|
};
|
||||||
|
|
||||||
eu.route(router, 'post' ,'/etapi/create-note', (req, res, next) => {
|
eu.route(router, 'post' ,'/etapi/create-note', (req, res, next) => {
|
||||||
const params = {};
|
const params = {};
|
||||||
|
|
||||||
eu.validateAndPatch(params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_NOTE);
|
eu.validateAndPatch(params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_NOTE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = noteService.createNewNote(params);
|
const resp = noteService.createNewNote(params);
|
||||||
|
|
||||||
res.json({
|
res.status(201).json({
|
||||||
note: mappers.mapNoteToPojo(resp.note),
|
note: mappers.mapNoteToPojo(resp.note),
|
||||||
branch: mappers.mapBranchToPojo(resp.branch)
|
branch: mappers.mapBranchToPojo(resp.branch)
|
||||||
});
|
});
|
||||||
|
@ -218,9 +218,10 @@ class NoteContext extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasNoteList() {
|
hasNoteList() {
|
||||||
return this.note.hasChildren()
|
return this.note
|
||||||
|
&& this.note.hasChildren()
|
||||||
&& ['book', 'text', 'code'].includes(this.note.type)
|
&& ['book', 'text', 'code'].includes(this.note.type)
|
||||||
&& this.note.mime !== 'text/x-sqlite;schema=trilium'
|
&& this.note.mime !== 'text/x-sqlite;schema=trilium'
|
||||||
&& !this.note.hasLabel('hideChildrenOverview');
|
&& !this.note.hasLabel('hideChildrenOverview');
|
||||||
|
@ -6,7 +6,7 @@ Content-Type: application/json
|
|||||||
}
|
}
|
||||||
|
|
||||||
> {%
|
> {%
|
||||||
client.assert(response.status === 200);
|
client.assert(response.status === 201);
|
||||||
|
|
||||||
client.global.set("authToken", response.body.authToken);
|
client.global.set("authToken", response.body.authToken);
|
||||||
%}
|
%}
|
||||||
|
@ -11,15 +11,15 @@ Content-Type: application/json
|
|||||||
"content": "Hi there!"
|
"content": "Hi there!"
|
||||||
}
|
}
|
||||||
|
|
||||||
> {%
|
> {%
|
||||||
client.assert(response.status === 200);
|
client.assert(response.status === 201);
|
||||||
client.assert(response.body.note.noteId.startsWith("forcedId"));
|
client.assert(response.body.note.noteId.startsWith("forcedId"));
|
||||||
client.assert(response.body.note.title == "Hello");
|
client.assert(response.body.note.title == "Hello");
|
||||||
client.assert(response.body.branch.branchId.startsWith("forcedId"));
|
client.assert(response.body.branch.branchId.startsWith("forcedId"));
|
||||||
client.assert(response.body.branch.parentNoteId == "root");
|
client.assert(response.body.branch.parentNoteId == "root");
|
||||||
|
|
||||||
client.log(`Created note ` + response.body.note.noteId + ` and branch ` + response.body.branch.branchId);
|
client.log(`Created note ` + response.body.note.noteId + ` and branch ` + response.body.branch.branchId);
|
||||||
|
|
||||||
client.global.set("createdNoteId", response.body.note.noteId);
|
client.global.set("createdNoteId", response.body.note.noteId);
|
||||||
client.global.set("createdBranchId", response.body.branch.branchId);
|
client.global.set("createdBranchId", response.body.branch.branchId);
|
||||||
%}
|
%}
|
||||||
@ -37,11 +37,11 @@ Content-Type: application/json
|
|||||||
}
|
}
|
||||||
|
|
||||||
> {%
|
> {%
|
||||||
client.assert(response.status === 200);
|
client.assert(response.status === 201);
|
||||||
client.assert(response.body.parentNoteId == "hidden");
|
client.assert(response.body.parentNoteId == "hidden");
|
||||||
|
|
||||||
client.global.set("clonedBranchId", response.body.branchId);
|
client.global.set("clonedBranchId", response.body.branchId);
|
||||||
|
|
||||||
client.log(`Created cloned branch ` + response.body.branchId);
|
client.log(`Created cloned branch ` + response.body.branchId);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
@ -107,9 +107,9 @@ Authorization: {{authToken}}
|
|||||||
}
|
}
|
||||||
|
|
||||||
> {%
|
> {%
|
||||||
client.assert(response.status === 200);
|
client.assert(response.status === 201);
|
||||||
client.assert(response.body.attributeId.startsWith("forcedAttributeId"));
|
client.assert(response.body.attributeId.startsWith("forcedAttributeId"));
|
||||||
|
|
||||||
client.global.set("createdAttributeId", response.body.attributeId);
|
client.global.set("createdAttributeId", response.body.attributeId);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
@ -121,4 +121,4 @@ Authorization: {{authToken}}
|
|||||||
> {%
|
> {%
|
||||||
client.assert(response.status === 200);
|
client.assert(response.status === 200);
|
||||||
client.assert(response.body.attributeId == client.global.get("createdAttributeId"));
|
client.assert(response.body.attributeId == client.global.get("createdAttributeId"));
|
||||||
%}
|
%}
|
||||||
|
@ -6,8 +6,8 @@ Content-Type: application/json
|
|||||||
}
|
}
|
||||||
|
|
||||||
> {%
|
> {%
|
||||||
client.assert(response.status === 200);
|
client.assert(response.status === 201);
|
||||||
|
|
||||||
client.global.set("testAuthToken", response.body.authToken);
|
client.global.set("testAuthToken", response.body.authToken);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
@ -31,4 +31,4 @@ Content-Type: application/json
|
|||||||
GET {{triliumHost}}/etapi/notes/root
|
GET {{triliumHost}}/etapi/notes/root
|
||||||
Authorization: {{testAuthToken}}
|
Authorization: {{testAuthToken}}
|
||||||
|
|
||||||
> {% client.assert(response.status === 401); %}
|
> {% client.assert(response.status === 401); %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user