feat: agregar funcionalidad para obtener organizaciones públicas y actualizar el sitemap con rutas dinámicas
This commit is contained in:
@@ -72,6 +72,8 @@ export class CompaniesAdapterMongoose implements ICompaniesAdapter {
|
||||
showPublicProfessionals: { type: Boolean, required: false, default: true },
|
||||
});
|
||||
|
||||
this.schema.index({ published: 1, banned: 1 });
|
||||
|
||||
this.companyList = model<ICompanyDocument>("Company", this.schema);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { isNull } from "../../helpers/IsNull";
|
||||
import CompaniesList from "../Companies/Companies";
|
||||
import { CompaniesAdapterMongoose } from "../Companies/Companies.Adapter.Mongoose";
|
||||
import ServiceList from "../Services/Service";
|
||||
import {
|
||||
PublicServicesResults,
|
||||
@@ -15,6 +16,24 @@ import { BotEventParams, BotView } from "../WapServer/WapServer.Interface";
|
||||
import WapServerList from "../WapServer/WapServer";
|
||||
import { COMPANY_PUBLISHED_STATUS } from "../Companies/Companies.Interface";
|
||||
|
||||
export type PublicOrganizationsParams = {
|
||||
page: number;
|
||||
limit: number;
|
||||
};
|
||||
|
||||
export type PublicOrganizationListItem = {
|
||||
slug: string;
|
||||
name: string;
|
||||
description: string;
|
||||
creationDate: Date;
|
||||
};
|
||||
|
||||
export type PublicOrganizationsResult = {
|
||||
data: PublicOrganizationListItem[];
|
||||
page: number;
|
||||
pages: number;
|
||||
};
|
||||
|
||||
export type HomeView = {
|
||||
education: PublicServicesResults;
|
||||
health: PublicServicesResults;
|
||||
@@ -39,6 +58,7 @@ export type PublicOrganizationViewParams = {
|
||||
|
||||
export type PublicOrganizationView = {
|
||||
id: string;
|
||||
slug: string;
|
||||
headerFile: string;
|
||||
headerColor: string;
|
||||
headerFontColor: string;
|
||||
@@ -143,6 +163,7 @@ class Views {
|
||||
|
||||
return {
|
||||
id: isNull<string>(company.id, ""),
|
||||
slug: isNull<string>(company.slug, ""),
|
||||
name: isNull<string>(company.name, ""),
|
||||
description: isNull<string>(company.description, ""),
|
||||
categoryId: isNull<number>(company.categoryId, 50000),
|
||||
@@ -249,6 +270,44 @@ class Views {
|
||||
};
|
||||
}
|
||||
|
||||
public async publicOrganizations(
|
||||
data: PublicOrganizationsParams
|
||||
): Promise<PublicOrganizationsResult> {
|
||||
const { page, limit } = data;
|
||||
const filter = {
|
||||
published: COMPANY_PUBLISHED_STATUS.PUBLISHED,
|
||||
banned: { $ne: true },
|
||||
};
|
||||
|
||||
const companyList = (CompaniesList.companies as CompaniesAdapterMongoose).companyList;
|
||||
|
||||
const count = await companyList
|
||||
.countDocuments(filter)
|
||||
.exec();
|
||||
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const results = (await companyList
|
||||
.find(filter)
|
||||
.select("slug name description creationDate")
|
||||
.sort({ creationDate: 1 })
|
||||
.skip(skip)
|
||||
.limit(limit)
|
||||
.lean()
|
||||
.exec()) as any[];
|
||||
|
||||
return {
|
||||
data: results.map((company) => ({
|
||||
slug: String(company.slug || ""),
|
||||
name: String(company.name || ""),
|
||||
description: String(company.description || ""),
|
||||
creationDate: company.creationDate,
|
||||
})),
|
||||
page,
|
||||
pages: Math.ceil(count / limit),
|
||||
};
|
||||
}
|
||||
|
||||
public async wapView(data: BotEventParams): Promise<BotView> {
|
||||
return await WapServerList.botView(data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user