Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running npm server produces error #10

Open
daveharmswebdev opened this issue Jul 30, 2020 · 4 comments
Open

running npm server produces error #10

daveharmswebdev opened this issue Jul 30, 2020 · 4 comments

Comments

@daveharmswebdev
Copy link

c:\git-repositories\github\ngrx-course>npm run server

angular-ngrx-course@0.0.0 server c:\git-repositories\github\ngrx-course
ts-node -P ./server/server.tsconfig.json ./server/server.ts

c:\git-repositories\github\ngrx-course\node_modules\ts-node\src\index.ts:307
throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
^
TSError: ⨯ Unable to compile TypeScript
server\search-lessons.route.ts (19,35): Argument of type 'string | ParsedQs | string[] | ParsedQs[]' is not assignable to parameter of type 'string'.
Type 'ParsedQs' is not assignable to type 'string'. (2345)
server\search-lessons.route.ts (20,33): Argument of type 'string | ParsedQs | string[] | ParsedQs[]' is not assignable to parameter of type 'string'.
Type 'ParsedQs' is not assignable to type 'string'. (2345)
server\search-lessons.route.ts (22,63): This condition will always return 'false' since the types 'number' and 'string | ParsedQs | string[] | ParsedQs[]' have no overlap. (2367)
server\search-lessons.route.ts (25,102): Property 'toLowerCase' does not exist on type 'string | ParsedQs | string[] | ParsedQs[]'.
Property 'toLowerCase' does not exist on type 'string[]'. (2339)
at getOutput (c:\git-repositories\github\ngrx-course\node_modules\ts-node\src\index.ts:307:15)
at c:\git-repositories\github\ngrx-course\node_modules\ts-node\src\index.ts:336:16
at Object.compile (c:\git-repositories\github\ngrx-course\node_modules\ts-node\src\index.ts:496:11)
at Module.m._compile (c:\git-repositories\github\ngrx-course\node_modules\ts-node\src\index.ts:392:43)
at Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Object.require.extensions. [as .ts] (c:\git-repositories\github\ngrx-course\node_modules\ts-node\src\index.ts:395:12)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! angular-ngrx-course@0.0.0 server: ts-node -P ./server/server.tsconfig.json ./server/server.ts
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular-ngrx-course@0.0.0 server script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\DHarms\AppData\Roaming\npm-cache_logs\2020-07-30T11_26_50_778Z-debug.log

c:\git-repositories\github\ngrx-course>

@daveharmswebdev
Copy link
Author

this is a windows pc with the latest verison of Node

@daveharmswebdev
Copy link
Author

this is in the 1-start branch

@daveharmswebdev
Copy link
Author

solved it by adding toString in three places




import {Request, Response} from 'express';
import {LESSONS} from "./db-data";
import {setTimeout} from "timers";



export function searchLessons(req: Request, res: Response) {

    console.log('Searching for lessons ...');

        const queryParams = req.query;

        const courseId = queryParams.courseId,
            filter = queryParams.filter || '',
            sortOrder = queryParams.sortOrder || 'asc',
            pageNumber = parseInt(queryParams.pageNumber.toString()) || 0, // added toString() here
            pageSize = parseInt(queryParams.pageSize.toString()); // added toString() here

        let lessons = Object.values(LESSONS).filter(lesson => lesson.courseId === +courseId).sort((l1, l2) => l1.id - l2.id);

        if (filter) {
            lessons = lessons.filter(lesson => lesson.description.trim().toLowerCase().search(filter.toString().toLowerCase()) >= 0); // added toString() here
        }

        if (sortOrder === 'desc') {
            lessons = lessons.reverse();
        }

        const initialPos = pageNumber * pageSize;

        console.log(`Retrieving lessons page starting at position ${initialPos}, page size ${pageSize} for course ${courseId}`);

        const lessonsPage = lessons.slice(initialPos, initialPos + pageSize);

        res.status(200).json(lessonsPage);

}

@kshab
Copy link

kshab commented Feb 1, 2021

Also you have transformed string to number (+courseId) in line 25. I've encountered the same issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants