Skip to content
Snippets Groups Projects
Verified Commit 903eb9d7 authored by Damien's avatar Damien
Browse files

FEAT #11991 TIME 0:30 Create notes content

parent c5d9a88f
No related branches found
No related tags found
No related merge requests found
-- *************************************************************************--
-- --
-- --
-- Model migration script - 19.09 to 20.XX --
-- --
-- --
-- *************************************************************************--
ALTER TABLE main_documents DROP COLUMN IF EXISTS notes;
ALTER TABLE main_documents ADD COLUMN notes jsonb;
......@@ -144,6 +144,7 @@ CREATE TABLE main_documents
description text,
sender text NOT NULL,
deadline timestamp without time zone,
notes jsonb
metadata jsonb NOT NULL DEFAULT '{}',
creation_date timestamp without time zone NOT NULL DEFAULT NOW(),
modification_date timestamp without time zone DEFAULT NOW(),
......
......@@ -151,6 +151,7 @@ class DocumentController
'reference' => $document['reference'],
'description' => $document['description'],
'sender' => $document['sender'],
'notes' => !empty($document['notes']) ? json_decode($document['notes'], true) : null,
'creationDate' => $document['creation_date'],
'modificationDate' => $document['modification_date'],
'pages' => $adr[0]['count']
......@@ -318,14 +319,24 @@ class DocumentController
return $response->withStatus(500)->withJson(['errors' => $storeInfos['errors']]);
}
if (!empty($body['notes']) && !empty($body['notes']['value'])) {
$notes = [
'value' => $body['notes']['value'],
'creator' => $body['notes']['creator'] ?? null,
'creationDate' => $body['notes']['creationDate'] ?? null
];
$notes = json_encode($notes);
}
DatabaseModel::beginTransaction();
$id = DocumentModel::create([
'title' => $body['title'],
'reference' => empty($body['reference']) ? null : $body['reference'],
'description' => empty($body['description']) ? null : $body['description'],
'sender' => $body['sender'],
'deadline' => empty($body['deadline']) ? null : $body['deadline'],
'metadata' => empty($body['metadata']) ? '{}' : json_encode($body['metadata'])
'title' => $body['title'],
'reference' => empty($body['reference']) ? null : $body['reference'],
'description' => empty($body['description']) ? null : $body['description'],
'sender' => $body['sender'],
'deadline' => empty($body['deadline']) ? null : $body['deadline'],
'notes' => $notes ?? null,
'metadata' => empty($body['metadata']) ? '{}' : json_encode($body['metadata'])
]);
AdrModel::createDocumentAdr([
......
......@@ -60,7 +60,7 @@ class DocumentModel
public static function create(array $args)
{
ValidatorModel::notEmpty($args, ['title', 'sender', 'metadata']);
ValidatorModel::stringType($args, ['title', 'reference', 'description', 'sender', 'deadline', 'metadata']);
ValidatorModel::stringType($args, ['title', 'reference', 'description', 'sender', 'deadline', 'notes', 'metadata']);
$nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'main_documents_id_seq']);
......@@ -73,6 +73,7 @@ class DocumentModel
'description' => $args['description'],
'sender' => $args['sender'],
'deadline' => $args['deadline'],
'notes' => $args['notes'],
'metadata' => $args['metadata']
]
]);
......@@ -80,30 +81,30 @@ class DocumentModel
return $nextSequenceId;
}
public static function update(array $aArgs)
public static function update(array $args)
{
ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']);
ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']);
ValidatorModel::notEmpty($args, ['set', 'where', 'data']);
ValidatorModel::arrayType($args, ['set', 'where', 'data']);
DatabaseModel::update([
'table' => 'main_documents',
'set' => $aArgs['set'],
'where' => $aArgs['where'],
'data' => $aArgs['data']
'set' => $args['set'],
'where' => $args['where'],
'data' => $args['data']
]);
return true;
}
public static function delete(array $aArgs)
public static function delete(array $args)
{
ValidatorModel::notEmpty($aArgs, ['where', 'data']);
ValidatorModel::arrayType($aArgs, ['where', 'data']);
ValidatorModel::notEmpty($args, ['where', 'data']);
ValidatorModel::arrayType($args, ['where', 'data']);
DatabaseModel::delete([
'table' => 'main_documents',
'where' => $aArgs['where'],
'data' => $aArgs['data']
'where' => $args['where'],
'data' => $args['data']
]);
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment