Skip to content

Commit

Permalink
ar(feat) sort it
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloreale committed Jul 13, 2024
1 parent bc7c85d commit f52d3b7
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 0 deletions.
60 changes: 60 additions & 0 deletions lib/model/interfaces/get-public-listings-iface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// @controller/get-public-listings-iface.ts
import { PublicPrisma } from '@model';

const PAGE_SIZE = 100;

const getPublicListings = async ({ page = 0, offset = 0, limit = PAGE_SIZE, filters = [] }: any) => {
const adaptQuery: any = {
skip: page * (limit + offset),
take: limit,
};

if (filters?.length) {
try {
const supportedTaxonomies: Record<string, any> = {
modalidade1: {
name: {
es: 'modalidade1',
},
nature: 'modalidades',
query: {
OR: [
{ taxonomies: { some: { name: { is: { es: 'Modalidad 1' } } } } },
{ listingTaxonomies: { some: { name: { is: { es: 'Modalidad 1' } } } } },
],
},
},
especie1: {
name: {
es: 'especie1',
},
nature: 'especies',
query: {
OR: [
{ taxonomies: { some: { name: { is: { es: 'Taxonomy Term 1' } } } } },
{ listingTaxonomies: { some: { name: { is: { es: 'Taxonomy Term 1' } } } } },
],
},
},
};

const query: any = filters?.reduce((acc: any, filter: string) => {
if (!acc.OR) acc.OR = [];
acc.OR.push(supportedTaxonomies[filter].query);
return acc;
}, {});

adaptQuery.where = {
...query,
};
} catch (e) {
throw new Error('Code 001: Wrong filter');
}
}

const response = await PublicPrisma.publicListings.findMany(adaptQuery);

return response;
};

export default getPublicListings;
4 changes: 4 additions & 0 deletions lib/model/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export { getUserMeta } from './mdb-get-interface';
// write
export { commitUpdate, initSignUpUser } from './mdb-update-interface';


/* prisma-public-ifaces */
export { default as GetPublicListings } from './get-public-listings-iface';

/* rm */

// read
Expand Down
120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f52d3b7

Please sign in to comment.