노드를 사용하여 작업판을 작성합니다.js와FaunaDB-제2부분
소개하다.
이 글은 제가 쓰고 있는 일련의 글의 두 번째 부분입니다. 이 글들은FaunaDB에서 공부하는 상황을 기록하고 있으며, 작업판에 API를 만들려고 노력하고 있습니다.
이 특정 부분에서 저는 지원자와 직위 채용에 사용되는 기술을 CRUD로 진행할 것입니다.
첫 번째 섹션입니다.

노드를 사용하여 작업판을 작성합니다.js와FaunaDB--제1부분
루이스 펠리페 조체타・ 20년 12월 6일・ 5분 읽기
만족하다
Module structure and objective :
모듈의 일부가 될 파일을 만들고 응용 프로그램에 추가합니다.
List skills :
나는 동물을 포함하는 문서를 열거하는 방법과 사용자에게 답안을 보내기 전에 답안을 정리하는 방법에 대해 토론했다.
Add skill :
Flora에 문서를 추가하는 방법.나는 또한 검증 모델의 함수를 만들었다.
Cleaning the response :
이 부분에서 사용자에게 보내기 전에 데이터베이스에서 얻은 결과를 삭제할 수 있는 함수를 만들었습니다.
Updating skill :
나는 동물군에 관한 문서를 어떻게 갱신하는지 계속 이야기한다
모듈 패브릭 및 타겟
I've decided to start from the skills because it seems like the easiest one, after all, it's model will only be a name.
First of all, I will create a folder named "Skills", inside it, I will create two files, routes.js and controller.js
I would usually also create a "db.js", but I really feel like this won't be necessary, as FaunaDB doesn't need much configuration, but I could be wrong on this.
Skill will be in the url: http://localhost/skills ;기본 경로 파일에 기술 경로를 추가했습니다.

이제 기술을 위한 세 가지 함수만 만들 수 있습니다.
기술 나열
For the list skills query, I will use this stackoverflow question를 기초로 한다.여기서 답을 수정하고 "listSkills"함수를 만들었습니다.

그 후에 나는 기술 노선에 노선을 만들었다.js 파일:

완성된 후에 나는 테스트를 시작했고 오류가 있다는 것을 깨달았다.
홈 라우터를 잘못된 이름으로 가져왔기 때문에 라우트로 수정했습니다.js:

컨트롤러에서 가져온 변수 유형을 설명하는 것도 잊었습니다.

이번에는 서버가 예상대로 실행되었지만, 어떤 이유로 응답이 없었기 때문에, 나는 나의 노선이 응답 목록이 아니라 목록으로 돌아가는 것임을 깨달았다.

이 오류를 수정하면 라우트가 예상대로 작동합니다.

계속하기 전에 이 정보를 정리하고 응답을 대상의 그룹으로 포맷하고 싶습니다.
{
name: "skillName", ref: "skillId"
}
그러나 이 응답을 정리하기 시작했을 때, 새로운 기술을 추가한 후 이 응답이 어떻게 될지 알 수 없기 때문에, 더 많은 문서를 추가한 후에 응답을 정리하기로 결정했습니다.스킬 증가
For inserting a skill, I will use this piece of documentation를 기초로 한다.나는 함수로 사용자로부터 받은 문서를 확인하고 정리함으로써 그들이 내가 원하지 않는 데이터 형식이나 전통적인 필드로 데이터베이스를 오염시키지 않도록 하기 시작했다.

검증은 매우 간단합니다. 기술이 있는지, 이름, 청결한 부분만 물어보고, 이름만 있는 새 대상을 만들고 문자열인지 확인합니다.

그래서 나는 나의 노선을 쓰기 시작했다. 나의 귀환이 http 상태를 이야기하는 것이 아니라는 것을 깨달았고 그래서 나는 귀환에 상태를 추가했다.



상태 400은 사용자가 나에게 잘못된 정보를 보냈음을 나타내고 상태 200은 모든 것이 정상임을 나타낸다.
완성된 후에 나는 다음과 같은 노선을 썼다.

지금은 우체부에 대한 시험이다.
먼저 인증을 테스트하기 위해 빈 요청을 보냈습니다.

그 후, 나는 안에 아무것도 없는 기술 물체를 사용해 보았다.

마지막으로 나는 통과해야 할 물체를 시도했다.

응답은 크지만 데이터가 정확하게 삽입된 것을 볼 수 있습니다.
응답 정리
Now that I can insert many skills easily, I will clean the responses, so it only countains the name and the reference for that skill.
To do that, I've created this function:

그리고 이를 통해 내가 데이터베이스에서 되돌아온 목록을 전달했다.

결과는 다음과 같습니다.

작업이 완료되면 이 함수를 삽입에 추가합니다.

또한 예상대로 작동합니다.

기술 갱신
The updating is mostly a copy form insertion, the difference is the query, that I will copy from this documentation인용이 존재하는지 검증해야 합니다.따라서 참조에 대한 검증을 추가했습니다.

업데이트된 질의를 변경했습니다.

업데이트된 코드를 모두 인쇄하지 않습니다. 너무 커서 화면에 맞지 않지만,github에 있습니다.
완료 후 노선을 만들었습니다.

우체부와 함께 테스트:

결론
이렇게 하면 기능 모듈이 완성된다. 다음 글에서 나는 다른 모듈부터 시작할 것이다. 이 모듈들은 더욱 재미있어야 한다. 왜냐하면 참고 자료와 더 복잡한 것을 배워야 하기 때문이다.
본 프로젝트의 Github 재구매 계약:
조체타 / 포나 작업대
Reference
이 문제에 관하여(노드를 사용하여 작업판을 작성합니다.js와FaunaDB-제2부분), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/ciochetta/creating-a-job-board-with-node-js-and-faunadb-part-2-1926텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)