From 320ae296e163534de353351db7e2cccb15709739 Mon Sep 17 00:00:00 2001 From: jamuchan Date: Thu, 1 Apr 2021 15:45:06 +0800 Subject: [PATCH] Add bible translation to bible verse. Update updated_date on post request. --- app/Services/CMS/BibleTranslationServices.js | 2 ++ app/Services/CMS/BibleVerseServices.js | 17 +++++++++------ .../1616835748390_bible_verses_schema.js | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 database/migrations/1616835748390_bible_verses_schema.js diff --git a/app/Services/CMS/BibleTranslationServices.js b/app/Services/CMS/BibleTranslationServices.js index 10de583..cb91daf 100644 --- a/app/Services/CMS/BibleTranslationServices.js +++ b/app/Services/CMS/BibleTranslationServices.js @@ -1,4 +1,5 @@ const BibleTranslation = use('App/Models/BibleTranslation') +const Database = use("Database") class BibleTranslationServices { async getAllBibleTranslation() { @@ -20,6 +21,7 @@ class BibleTranslationServices { async updateBibleTranslation({ id, info }) { const translation = this.createModelObject(info) + translation.updated_at = Database.fn.now() const result = await BibleTranslation.query().where('id', id).update(translation) return result } diff --git a/app/Services/CMS/BibleVerseServices.js b/app/Services/CMS/BibleVerseServices.js index 9d28b70..b79bf1e 100644 --- a/app/Services/CMS/BibleVerseServices.js +++ b/app/Services/CMS/BibleVerseServices.js @@ -4,7 +4,7 @@ const Database = use("Database"); class BibleVerseServices { async createBibleVerse({ info }) { - const { book, chapter, verse_no, details, keywords } = info; + const { book, chapter, verse_no, details, keywords, translation_id } = info; const bverses = new BibleVerses(); @@ -12,10 +12,11 @@ class BibleVerseServices { bverses.chapter = chapter; bverses.verse_no = verse_no; bverses.details = details; + bverses.translation_id = translation_id; const result = await bverses.save(); const last_row = await BibleVerses.last(); - + for (const keyword of keywords) { await this.createKeywords({ id: last_row.id, @@ -24,7 +25,7 @@ class BibleVerseServices { } return result; - + } async createKeywords({ id, keywords }) { @@ -41,12 +42,16 @@ class BibleVerseServices { } async updateBibleVerseInfo({ id, req }) { + const data = { + updated_at: Database.fn.now(), + ...req, + } const affectedRows = await Database.table('bible_verses') .where('id', id) - .update(req); - + .update(data); + return affectedRows; } } -module.exports = BibleVerseServices; \ No newline at end of file +module.exports = BibleVerseServices; diff --git a/database/migrations/1616835748390_bible_verses_schema.js b/database/migrations/1616835748390_bible_verses_schema.js new file mode 100644 index 0000000..d7b3db0 --- /dev/null +++ b/database/migrations/1616835748390_bible_verses_schema.js @@ -0,0 +1,21 @@ +'use strict' + +/** @type {import('@adonisjs/lucid/src/Schema')} */ +const Schema = use('Schema') + +class BibleVersesSchema extends Schema { + up () { + this.table('bible_verses', (table) => { + table.string('translation_id').after('details') + table.foreign('translation_id').references('bible_translations.id') + }) + } + + down () { + this.table('bible_verses', (table) => { + table.dropColumn('translation_id') + }) + } +} + +module.exports = BibleVersesSchema