Skip to content

Commit

Permalink
added applyQueryParseOutput function + issue templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Oct 25, 2021
1 parent f7f3bd7 commit ad0d582
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 12 deletions.
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.md
@@ -0,0 +1,33 @@
---
name: 🚨 Bug report
about: Report a bug report, to improve this project.
title: 'Bug: '
labels: 'bug-report'
assignees: ''

---

<!-- 💚 Thanks for your time to make this project better with your feedback 💚
**IMPORTANT** Before reporting a bug:
👍 A properly detailed bug report can save a LOT of time and help fixing issues as soon as possible.
-->

### Versions
- Node: <!-- e.g. Node 16 -->
- OS: <!-- e.g. Windows 99> -->

### Reproduction

<details open>
<summary>Additional Details</summary>
</details>

### Steps to reproduce


### What is Expected?


### What is actually happening?
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,6 @@
blank_issues_enabled: false
contact_links:
- name: ❗️ All other issues
url: https://github.com/PHT-Medic/central-ui/discussions
about: |
Please use GitHub Discussions for other issues and asking questions.
26 changes: 26 additions & 0 deletions .github/ISSUE_TEMPLATE/suggest-a-feature.md
@@ -0,0 +1,26 @@
---
name: 🧠 Feature request
about: Suggest an idea or enhancement for this project
title: 'Feature: '
labels: 'feature-request'
assignees: ''

---

<!-- 💚 Thanks for your time to make this project better with your feedback 💚 -->

### Is your feature request related to a problem? Please describe.

<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->

### Describe the solution you'd like

<!-- A clear and concise description of what you want to happen. Adding some code examples would be neat! -->

### Describe alternatives you've considered

<!-- A clear and concise description of any alternative solutions or features you've considered. -->

### Additional context

<!-- Add any other context or screenshots about the feature request here. -->
4 changes: 4 additions & 0 deletions SECURITY.md
@@ -0,0 +1,4 @@
# Security Policy
## Reporting a Vulnerability

If you discover a security vulnerability regarding this project, please e-mail me to contact@tada5hi.net!
1 change: 1 addition & 0 deletions src/query/index.ts
@@ -1,4 +1,5 @@
export * from './parameter';
export * from './utils';



Expand Down
4 changes: 2 additions & 2 deletions src/query/parameter/fields/module.ts
Expand Up @@ -13,7 +13,7 @@ import {FieldsApplyOptions, FieldsApplyOutput} from "./type";
* @param data
*/
/* istanbul ignore next */
export function applyParsedQueryFields<T>(
export function applyQueryFieldsParseOutput<T>(
query: SelectQueryBuilder<T>,
data: FieldsApplyOutput
) {
Expand Down Expand Up @@ -53,7 +53,7 @@ export function applyQueryFields<T>(
data: unknown,
options?: FieldsApplyOptions
) : FieldsApplyOutput {
return applyParsedQueryFields(query, parseQueryFields(data, options));
return applyQueryFieldsParseOutput(query, parseQueryFields(data, options));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/query/parameter/pagination/module.ts
Expand Up @@ -8,7 +8,7 @@ import {PaginationApplyOptions, PaginationApplyOutput} from "./type";
* @param query
* @param data
*/
export function applyParsedQueryPagination<T>(
export function applyQueryPaginationParseOutput<T>(
query: SelectQueryBuilder<T>,
data: PaginationApplyOutput
) {
Expand Down Expand Up @@ -41,7 +41,7 @@ export function applyQueryPagination<T>(
data: unknown,
options?: PaginationApplyOptions
) : PaginationApplyOutput {
return applyParsedQueryPagination(query, parseQueryPagination(data, options));
return applyQueryPaginationParseOutput(query, parseQueryPagination(data, options));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/query/parameter/relations/module.ts
Expand Up @@ -8,7 +8,7 @@ import {RelationsApplyOptions, RelationsApplyOutput} from "./type";
* @param query
* @param data
*/
export function applyParsedQueryRelations<T>(
export function applyQueryRelationsParseOutput<T>(
query: SelectQueryBuilder<T>,
data: RelationsParseOutput
) : RelationsApplyOutput {
Expand All @@ -32,7 +32,7 @@ export function applyQueryRelations<T>(
data: unknown,
options?: RelationsApplyOptions
) : RelationsApplyOutput {
return applyParsedQueryRelations(query, parseQueryRelations(data, options));
return applyQueryRelationsParseOutput(query, parseQueryRelations(data, options));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/query/parameter/sort/module.ts
Expand Up @@ -10,7 +10,7 @@ import {SortApplyOptions, SortApplyOutput} from "./type";
* @param query
* @param data
*/
export function applyParsedQuerySort<T>(
export function applyQuerySortParseOutput<T>(
query: SelectQueryBuilder<T>,
data: SortParseOutput
) : SortApplyOutput {
Expand Down Expand Up @@ -44,7 +44,7 @@ export function applyQuerySort<T>(
data: unknown,
options?: SortApplyOptions
) : SortParseOutput {
return applyParsedQuerySort(query, parseQuerySort(data, options));
return applyQuerySortParseOutput(query, parseQuerySort(data, options));
}

/**
Expand All @@ -59,6 +59,6 @@ export function applySort<T>(
data: unknown,
options?: SortApplyOptions
) : SortParseOutput {
return applyParsedQuerySort(query, parseQuerySort(data, options));
return applyQuerySortParseOutput(query, parseQuerySort(data, options));
}

37 changes: 37 additions & 0 deletions src/query/utils.ts
@@ -0,0 +1,37 @@
import {Parameter, ParameterType, ParseOutput} from "@trapi/query";

import {
applyQueryFieldsParseOutput,
applyQueryPaginationParseOutput,
applyQueryRelationsParseOutput,
applyQueryFiltersParseOutput
} from "./parameter";

import {SelectQueryBuilder} from "typeorm";

export function applyQueryParseOutput<T>(
query: SelectQueryBuilder<T>,
context: ParseOutput
) : ParseOutput {
for(const key in context) {
switch (key as ParameterType) {
case Parameter.FIELDS:
applyQueryFieldsParseOutput(query, context.fields);
break;
case Parameter.FILTERS:
applyQueryFiltersParseOutput(query, context.filters);
break;
case Parameter.PAGINATION:
applyQueryPaginationParseOutput(query, context.pagination);
break;
case Parameter.RELATIONS:
applyQueryRelationsParseOutput(query, context.relations);
break;
case Parameter.SORT:
applyQueryRelationsParseOutput(query, context.sort);
break;
}
}

return context;
}
24 changes: 24 additions & 0 deletions test/unit/api/index.spec.ts
@@ -0,0 +1,24 @@
import {FakeSelectQueryBuilder} from "../../data/typeorm/FakeSelectQueryBuilder";
import {applyQueryParseOutput} from "../../../src";

describe('src/api/sort.ts', () => {
const query = new FakeSelectQueryBuilder();

it('should apply query output', () => {
const data = applyQueryParseOutput(query, {
relations: [],
fields: [],
filters: [],
pagination: {},
sort: []
});

expect(data).toEqual({
relations: [],
fields: [],
filters: [],
pagination: {},
sort: []
});
});
});
6 changes: 3 additions & 3 deletions test/unit/api/sort.spec.ts
@@ -1,14 +1,14 @@
import {parseQuerySort} from "@trapi/query";
import {applyQuerySort, applyParsedQuerySort, applySort} from "../../../src";
import {applyQuerySort, applyQuerySortParseOutput, applySort} from "../../../src";
import {FakeSelectQueryBuilder} from "../../data/typeorm/FakeSelectQueryBuilder";

describe('src/api/sort.ts', () => {
const query = new FakeSelectQueryBuilder();
it('should apply sort transformed', () => {
let data = applyParsedQuerySort(query, parseQuerySort('id', {allowed: ['id']}));
let data = applyQuerySortParseOutput(query, parseQuerySort('id', {allowed: ['id']}));
expect(data).toBeDefined();

data = applyParsedQuerySort(query, []);
data = applyQuerySortParseOutput(query, []);
expect(data).toEqual([]);
});

Expand Down

0 comments on commit ad0d582

Please sign in to comment.