This commit is contained in:
parent
f828ca4491
commit
cb51a4136f
167 changed files with 21485 additions and 21212 deletions
|
@ -1,9 +1,9 @@
|
|||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
||||
import Database from '@ioc:Adonis/Lucid/Database';
|
||||
import type { HttpContext } from '@adonisjs/core/http';
|
||||
import db from '@adonisjs/lucid/services/db';
|
||||
import { StatusCodes } from 'http-status-codes';
|
||||
|
||||
export default class HomeController {
|
||||
public async findDocumentsPerYear({ response, params }: HttpContextContract) {
|
||||
public async findDocumentsPerYear({ response, params }: HttpContext) {
|
||||
const year = params.year;
|
||||
const from = parseInt(year);
|
||||
const serverState = 'published';
|
||||
|
@ -17,8 +17,8 @@ export default class HomeController {
|
|||
// .preload('authors')
|
||||
// .orderBy('server_date_published');
|
||||
|
||||
const datasets = await Database.from('documents as doc')
|
||||
.select(['publish_id', 'server_date_published', Database.raw(`date_part('year', server_date_published) as pub_year`)])
|
||||
const datasets = await db.from('documents as doc')
|
||||
.select(['publish_id', 'server_date_published', db.raw(`date_part('year', server_date_published) as pub_year`)])
|
||||
.where('server_state', serverState)
|
||||
.innerJoin('link_documents_persons as ba', 'doc.id', 'ba.document_id')
|
||||
.andWhereRaw(`date_part('year', server_date_published) = ?`, [from])
|
||||
|
@ -32,17 +32,17 @@ export default class HomeController {
|
|||
}
|
||||
}
|
||||
|
||||
public async findYears({ response }: HttpContextContract) {
|
||||
public async findYears({ response }: HttpContext) {
|
||||
const serverState = 'published';
|
||||
// Use raw SQL queries to select all cars which belongs to the user
|
||||
try {
|
||||
const datasets = await Database.rawQuery(
|
||||
const datasets = await db.rawQuery(
|
||||
'SELECT distinct EXTRACT(YEAR FROM server_date_published) as published_date FROM gba.documents WHERE server_state = ?',
|
||||
[serverState],
|
||||
);
|
||||
|
||||
// Pluck the ids of the cars
|
||||
const years = datasets.rows.map((dataset) => dataset.published_date);
|
||||
const years = datasets.rows.map((dataset: any) => dataset.published_date);
|
||||
// check if the cars is returned
|
||||
// if (years.length > 0) {
|
||||
return response.status(StatusCodes.OK).json(years);
|
||||
|
@ -54,7 +54,7 @@ export default class HomeController {
|
|||
}
|
||||
}
|
||||
|
||||
public async findPublicationsPerMonth({ response }: HttpContextContract) {
|
||||
public async findPublicationsPerMonth({ response }: HttpContext) {
|
||||
const serverState = 'published';
|
||||
// const year = params.year;
|
||||
// const from = parseInt(year);
|
||||
|
@ -70,11 +70,11 @@ export default class HomeController {
|
|||
|
||||
const years = [2021, 2022, 2023]; // Add the second year
|
||||
|
||||
const result = await Database.from('documents as doc')
|
||||
const result = await db.from('documents as doc')
|
||||
.select([
|
||||
Database.raw(`date_part('year', server_date_published) as pub_year`),
|
||||
Database.raw(`date_part('month', server_date_published) as pub_month`),
|
||||
Database.raw('COUNT(*) as count'),
|
||||
db.raw(`date_part('year', server_date_published) as pub_year`),
|
||||
db.raw(`date_part('month', server_date_published) as pub_month`),
|
||||
db.raw('COUNT(*) as count'),
|
||||
])
|
||||
.where('server_state', serverState)
|
||||
// .innerJoin('link_documents_persons as ba', 'doc.id', 'ba.document_id')
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue