Skip to content

Commit

Permalink
updatePagination
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbrui committed Apr 19, 2024
1 parent e3e543a commit 125f6b3
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 47 deletions.
27 changes: 13 additions & 14 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"root": true,
{
"parser": "@typescript-eslint/parser", // Specifies the ESLint parser
"extends": [
"prettier",
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"parserOptions": {
"ecmaVersion": 2018, // Allows for the parsing of modern ECMAScript features
"sourceType": "module" // Allows for the use of imports
},
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
]
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/explicit-module-boundary-types": 0
}
}
19 changes: 19 additions & 0 deletions .eslintrc2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"root": true,
"extends": [
"prettier",
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
]
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
lib
node_modules
.graphql-editor-auth.json
tsconfig.tsbuildinfo
tsconfig.tsbuildinfo
.vscode
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/integrations/gei-bookings/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gei-bookings",
"version": "0.2.6",
"version": "0.2.7",
"description": "Automatically generated by graphql-editor-cli",
"main": "lib/index.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const getService = async (input: FieldResolveInput) =>
resolverFor('PublicQuery', 'getService', async (args) =>
errMiddleware(async () => {
return ({
service: convertDatedObjToString(await MongoOrb('Services').collection.findOne({ _id: args.serviceId, active: { $ne: false } }).catch((r) => {
throw new GlobalError(r, import.meta.url);
service: convertDatedObjToString(await MongoOrb('Services').collection.findOne({ _id: args.serviceId, active: { $ne: false } }).catch((r) => {
throw new GlobalError(r, import.meta.url);
}))
})
}),
Expand Down
32 changes: 19 additions & 13 deletions packages/integrations/gei-bookings/src/PublicQuery/listServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ export const listServices = async (input: FieldResolveInput) =>
errMiddleware(async () => {
const po = preparePageOptions(args?.input?.page);
const inputFilters = inputServiceFiltersSet(args?.input?.filters)
return {
services: convertDateObjToStringForArray(await MongoOrb(ServicesCollection)
.collection.find({
...inputFilters,
active: { $ne: false },
taken: { $ne: true },
})
.limit(po.limit)
.skip(po.skip)
.sort('createdAt', -1)
.toArray(),
)};
}),
const servicesCursor = MongoOrb(ServicesCollection)
.collection.find({
...inputFilters,
active: { $ne: false },
taken: { $ne: true },
})
const paginatedServices = await (po.limit < 1 ?
servicesCursor
: servicesCursor.limit(po.limit + 1).skip(po.skip)
).sort('createdAt', -1)
.toArray()
const hasNext = paginatedServices.length === po.limit + 1
if(hasNext) paginatedServices.pop();

return {
services: convertDateObjToStringForArray(paginatedServices),
hasNextPage: hasNext
};
}),
)(input.arguments);
export default listServices;
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ export const getBookingsForService = async (input: FieldResolveInput) =>
.toArray()
.then((s) => s.map((ss) => ss._id))

const bookings = await MongoOrb('Bookings')
.collection.find({ ...inputFilters, services: { $in: ownedServices } })
.limit(po.limit)
.skip(po.skip)
.sort('createdAt', -1)
.toArray()

return { books: convertDateObjToStringForArray<BookingRecordModel>(await MongoOrb('Bookings').composeRelated(bookings, 'services', 'Services', '_id')) }
const bookingsCursor = MongoOrb('Bookings')
.collection.find({ ...inputFilters, services: { $in: ownedServices } })
const paginatedBookings = await (po.limit < 1 ?
bookingsCursor
: bookingsCursor.limit(po.limit + 1).skip(po.skip)
).sort('createdAt', -1)
.toArray()
const hasNext = paginatedBookings.length === po.limit + 1
if(hasNext) paginatedBookings.pop();



return {
books: convertDateObjToStringForArray<BookingRecordModel>(await MongoOrb('Bookings').composeRelated(paginatedBookings, 'services', 'Services', '_id')),
hasNextPage: hasNext
}
}),
)(input.arguments, input.source);
export default getBookingsForService;
23 changes: 14 additions & 9 deletions packages/integrations/gei-bookings/src/UserQuery/getSelfBooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ export const getSelfBooks = async (input: FieldResolveInput) =>
const po = preparePageOptions(args?.input?.page);
const inputFilters = inputBooksFiltersSet(args?.input?.filters)

return {
books: convertDateObjToStringForArray(await MongoOrb('Bookings')
.collection.find({ ...inputFilters, bookerId: src.userId || src._id })
.skip(po.skip)
.limit(po.limit)
.sort('createdAt', -1)
.toArray()
.then(async (b) => MongoOrb('Bookings').composeRelated(b, 'services', 'Services', '_id'))),
};
const bookingsCursor = MongoOrb('Bookings')
.collection.find({ ...inputFilters, bookerId: src.userId || src._id })
const paginatedBookings = await (po.limit < 1 ?
bookingsCursor
: bookingsCursor.limit(po.limit + 1).skip(po.skip)
).sort('createdAt', -1)
.toArray()
const hasNext = paginatedBookings.length === po.limit + 1
if(hasNext) paginatedBookings.pop();

return {
books: convertDateObjToStringForArray(await MongoOrb('Bookings').composeRelated(paginatedBookings, 'services', 'Services', '_id')),
hasNextPage: hasNext
}
}),
)(input.arguments, input.source);
export default getSelfBooks;

0 comments on commit 125f6b3

Please sign in to comment.