generated from techmmunity/base-project-serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20cb78d
commit 3b54027
Showing
43 changed files
with
920 additions
and
607 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DYNAMODB_ACCESS_KEY_ID= | ||
DYNAMODB_SECRET_ACCESS_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ lerna-debug.log* | |
# Enviroment | ||
*.env* | ||
!.env.docker | ||
!.env.sample | ||
|
||
# Core | ||
src/core | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,6 @@ | ||
# Techmmunity - Base Project Serverless | ||
# Techmmunity - Course Service | ||
|
||
[![CodeFactor](https://www.codefactor.io/repository/github/techmmunity/base-project-serverless/badge)](https://www.codefactor.io/repository/github/techmmunity/base-project-serverless) | ||
[![CodeFactor](https://www.codefactor.io/repository/github/techmmunity/course-service/badge)](https://www.codefactor.io/repository/github/techmmunity/course-service) | ||
[![DeepScan grade](https://deepscan.io/api/teams/13883/projects/17602/branches/407704/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=13883&pid=17602&bid=407704) | ||
[![Coverage Status](https://coveralls.io/repos/github/techmmunity/base-project-serverless/badge.svg?branch=master)](https://coveralls.io/github/techmmunity/base-project-serverless?branch=master) | ||
[![tests](https://github.com/techmmunity/base-project-serverless/actions/workflows/tests.yml/badge.svg)](https://github.com/techmmunity/base-project-serverless/actions/workflows/tests.yml) | ||
|
||
## TODO | ||
|
||
- [ ] Add Dynamo Integration | ||
- [ ] Config Serverless Framework correctly | ||
- [ ] Test Cognito Integration | ||
- [ ] Add Unit Tests | ||
[![Coverage Status](https://coveralls.io/repos/github/techmmunity/course-service/badge.svg?branch=master)](https://coveralls.io/github/techmmunity/course-service?branch=master) | ||
[![tests](https://github.com/techmmunity/course-service/actions/workflows/tests.yml/badge.svg)](https://github.com/techmmunity/course-service/actions/workflows/tests.yml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Body, Controller, Post } from "@nestjs/common"; | ||
import { CourseService } from "./course.service"; | ||
import { V1CreateCourseInputSchema } from "./service/create/schemas/input.schema"; | ||
import { API_VERSION } from "v1/config"; | ||
|
||
@Controller(`${API_VERSION}/course`) | ||
export class CourseController { | ||
public constructor(private readonly exampleService: CourseService) {} | ||
|
||
@Post() | ||
public create(@Body() data: V1CreateCourseInputSchema) { | ||
return this.exampleService.create(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { SymbiosisModule } from "@techmmunity/symbiosis-nestjs"; | ||
|
||
import { CourseEntity } from "v1/entities/course"; | ||
|
||
import { CourseService } from "./course.service"; | ||
import { CourseController } from "./course.controller"; | ||
|
||
@Module({ | ||
imports: [SymbiosisModule.forFeature([CourseEntity])], | ||
providers: [CourseService], | ||
controllers: [CourseController], | ||
}) | ||
export class CourseModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { InjectRepository } from "@techmmunity/symbiosis-nestjs"; | ||
|
||
import { CourseEntity, CourseRepository } from "v1/entities/course"; | ||
|
||
import { create } from "./service/create"; | ||
import { V1CreateCourseInputSchema } from "./service/create/schemas/input.schema"; | ||
|
||
@Injectable() | ||
export class CourseService { | ||
public constructor( | ||
@InjectRepository(CourseEntity) | ||
private readonly courseRepository: CourseRepository, | ||
) {} | ||
|
||
public create(params: V1CreateCourseInputSchema) { | ||
return create( | ||
{ | ||
courseRepository: this.courseRepository, | ||
}, | ||
params, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { CourseRepository } from "v1/entities/course"; | ||
import { V1CreateCourseInputSchema } from "./schemas/input.schema"; | ||
|
||
import { validate } from "./validate"; | ||
|
||
interface Injectables { | ||
courseRepository: CourseRepository; | ||
} | ||
|
||
export const create = async ( | ||
{ courseRepository }: Injectables, | ||
params: V1CreateCourseInputSchema, | ||
) => { | ||
const data = await validate(params); | ||
|
||
return courseRepository.save(data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { ResourceTypeEnum } from "v1/enums/resource-type"; | ||
import { SeniorityEnum } from "v1/enums/seniority"; | ||
|
||
class V1CreateCourseEpisodeQuizAnswerInputSchema { | ||
public answer: string; | ||
} | ||
|
||
class V1CreateCourseEpisodeQuizInputSchema { | ||
public question: string; | ||
|
||
public shortDescription: string; | ||
|
||
public rightAnswerId: string; | ||
|
||
public answers: Array<V1CreateCourseEpisodeQuizAnswerInputSchema>; | ||
} | ||
|
||
class V1CreateCourseEpisodeResourceInputSchema { | ||
public type: ResourceTypeEnum; | ||
|
||
public url?: string; | ||
|
||
public title?: string; | ||
|
||
public description?: string; | ||
} | ||
|
||
class V1CreateCourseEpisodeVideoInputSchema { | ||
public durationInSeconds: number; | ||
|
||
public previewImageUrl: string; | ||
|
||
public url: string; | ||
|
||
public version: number; | ||
} | ||
|
||
class V1CreateCourseEpisodeInputSchema { | ||
public name: string; | ||
|
||
public note: string; | ||
|
||
public video: V1CreateCourseEpisodeVideoInputSchema; | ||
|
||
public resources: Array<V1CreateCourseEpisodeResourceInputSchema>; | ||
|
||
public quizzes: Array<V1CreateCourseEpisodeQuizInputSchema>; | ||
} | ||
|
||
export class V1CreateCourseInputSchema { | ||
public name: string; | ||
|
||
public description: string; | ||
|
||
public mustKnowBefore?: Array<string>; | ||
|
||
public whereToGoAfter?: Array<string>; | ||
|
||
public available?: boolean; | ||
|
||
public seniority: SeniorityEnum; | ||
|
||
public toolkit: Array<string>; | ||
|
||
public tags: Array<string>; | ||
|
||
public episodes: Array<V1CreateCourseEpisodeInputSchema>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class V1CreateCourseOutputSchema { | ||
public thisIsAnParam: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* eslint-disable @typescript-eslint/no-magic-numbers */ | ||
|
||
import { fields } from "v1/validation/fields"; | ||
import { V1CreateCourseInputSchema } from "./schemas/input.schema"; | ||
|
||
import { makeValidate } from "v1/validation/validate"; | ||
import { yup } from "v1/utils/yup"; | ||
|
||
const { episodes } = fields; | ||
|
||
const schema = yup | ||
.object() | ||
.required() | ||
.strict() | ||
.shape({ | ||
name: fields.name.required(), | ||
description: fields.description.required(), | ||
mustKnowBefore: fields.mustKnowBefore.notRequired(), | ||
whereToGoAfter: fields.whereToGoAfter.notRequired(), | ||
available: fields.available.notRequired(), | ||
seniority: fields.seniority.required(), | ||
toolkit: fields.toolkit.required().min(1), | ||
tags: fields.tags.required().min(1), | ||
episodes: yup | ||
.array() | ||
.strict() | ||
.required() | ||
.of( | ||
yup | ||
.object() | ||
.strict() | ||
.required() | ||
.shape({ | ||
name: episodes.name.required(), | ||
note: episodes.note.required(), | ||
video: yup.object().strict().required().shape({ | ||
durationInSeconds: episodes.video.durationInSeconds.required(), | ||
previewImageUrl: episodes.video.previewImageUrl.required(), | ||
url: episodes.video.url.required(), | ||
version: episodes.video.version.required(), | ||
}), | ||
resources: yup | ||
.array() | ||
.strict() | ||
.required() | ||
.of( | ||
yup.object().strict().required().shape({ | ||
title: episodes.resources.title.notRequired(), | ||
description: episodes.resources.description.notRequired(), | ||
url: episodes.resources.url.notRequired(), | ||
previewImageUrl: | ||
episodes.resources.previewImageUrl.notRequired(), | ||
type: episodes.resources.type.required(), | ||
}), | ||
), | ||
quizzes: yup | ||
.array() | ||
.strict() | ||
.required() | ||
.of( | ||
yup | ||
.object() | ||
.strict() | ||
.required() | ||
.shape({ | ||
question: episodes.quizzes.question.required(), | ||
rightAnswerId: episodes.quizzes.rightAnswerId.required(), | ||
shortDescription: | ||
episodes.quizzes.shortDescription.required(), | ||
answers: yup | ||
.array() | ||
.strict() | ||
.required() | ||
.of( | ||
yup.object().strict().required().shape({ | ||
answer: episodes.quizzes.answers.answer.required(), | ||
}), | ||
) | ||
.min(2), | ||
}), | ||
), | ||
}), | ||
), | ||
}); | ||
|
||
export const validate = makeValidate<V1CreateCourseInputSchema>(schema); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.