first commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { FindPartidosParams, IPartidosAdapter, IPartido } from "./Partidos.interface";
|
||||
import { Document, Model, Schema, model } from "mongoose";
|
||||
|
||||
export interface IPartidoDocument extends Omit<IPartido, "id">, Document {}
|
||||
|
||||
export class PartidosAdapterMongoose implements IPartidosAdapter {
|
||||
schema: Schema;
|
||||
partidoList: Model<IPartidoDocument>;
|
||||
|
||||
constructor() {
|
||||
this.schema = new Schema({
|
||||
name: { type: String, required: true, unique: true },
|
||||
code: { type: Number, required: true, default: 0 },
|
||||
provincia: { type: String, required: true },
|
||||
latitude: { type: Number, required: true, default: 0 },
|
||||
longitude: { type: Number, required: true, default: 0 },
|
||||
});
|
||||
|
||||
this.partidoList = model<IPartidoDocument>("Partido", this.schema);
|
||||
}
|
||||
|
||||
public async find(filters: FindPartidosParams): Promise<IPartido[]> {
|
||||
return this.partidoList.find(filters).exec();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { TextObjectFilterResult } from "../TextObjectFilter.model";
|
||||
|
||||
export type FindPartidosParams = {
|
||||
_id?: string;
|
||||
name?: string;
|
||||
code?: number;
|
||||
provincia: string;
|
||||
};
|
||||
|
||||
export interface IPartido {
|
||||
id?: string;
|
||||
name: string;
|
||||
code: number;
|
||||
provincia: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
}
|
||||
|
||||
export interface IPartidosAdapter {
|
||||
find(filters: FindPartidosParams): Promise<IPartido[]>;
|
||||
}
|
||||
|
||||
export interface IPartidosManager {
|
||||
partidos: IPartidosAdapter;
|
||||
filterAll(data: FindPartidosParams): Promise<TextObjectFilterResult[]>;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { TextObjectFilterResult } from "../../Models/TextObjectFilter.model";
|
||||
import { PartidosAdapterMongoose } from "./Partidos.Adapter.Mongoose";
|
||||
import { FindPartidosParams, IPartidosManager } from "./Partidos.interface";
|
||||
|
||||
class PartidosManager implements IPartidosManager {
|
||||
partidos: PartidosAdapterMongoose;
|
||||
|
||||
constructor() {
|
||||
this.partidos = new PartidosAdapterMongoose();
|
||||
}
|
||||
|
||||
public async filterAll(data: FindPartidosParams): Promise<TextObjectFilterResult[]> {
|
||||
const partidos = await this.partidos.find(data);
|
||||
const returnData: TextObjectFilterResult[] = [];
|
||||
|
||||
for (const partido of partidos) {
|
||||
returnData.push({
|
||||
id: partido.name,
|
||||
name: partido.name.toLowerCase(),
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
}
|
||||
|
||||
const PartidosList = new PartidosManager();
|
||||
|
||||
export default PartidosList;
|
||||
Reference in New Issue
Block a user