forked from juliomoura-ilia/desafio-ilia
-
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
4b58db2
commit fa6deee
Showing
13 changed files
with
5,782 additions
and
25 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,5 @@ | ||
node_modules | ||
npm-debug.log | ||
.DS_Store | ||
.env | ||
.git |
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 @@ | ||
PORT=80 |
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 @@ | ||
PORT=80 |
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 @@ | ||
node_modules |
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,23 @@ | ||
# Use an official Node.js runtime as a parent image | ||
FROM node:14 | ||
|
||
# Set the working directory to /app | ||
WORKDIR /app | ||
|
||
# Copy package.json and package-lock.json to the working directory | ||
COPY package*.json ./ | ||
|
||
# Install app dependencies | ||
RUN npm install | ||
|
||
# Copy the current directory contents into the container at /app | ||
COPY . . | ||
|
||
# Make port 3000 available to the world outside this container | ||
EXPOSE 80 | ||
|
||
# Define environment variable | ||
ENV NODE_ENV=production | ||
|
||
# Run app.js when the container launches | ||
CMD ["node", "index.js"] |
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,30 +1,10 @@ | ||
# Ília - Desafio Técnico | ||
|
||
## Descrição | ||
Olá, e obrigado por aceitar realizar o desafio técnico do nosso processo seletivo! (: | ||
## Solution | ||
|
||
O desafio consiste na implementação de uma API de folha de ponto, descrita em api.yaml. Todas as informações necessárias sobre a construção da API estão contidas nesse arquivo. | ||
To start the server run `npm run start` | ||
To run the API tests run `npm run test` | ||
|
||
O desafio será testado usando Docker. Certifique-se de que todo o ambiente necessário para a execução do projeto esteja descrito de maneira que seja possível testar o projeto apenas criando um container. | ||
Enviroment variables should be saved in a `.env` file, an example of this file is located at `env.example`. However no variables are required in order to run the project or its tests. | ||
|
||
A API pode ser visualizada utilizando o [Swagger Editor](https://editor.swagger.io) com o arquivo yaml fornecido. | ||
|
||
## Q&A | ||
### Qual framework/linguagem devo utilizar? | ||
Para facilitar a avaliação do desafio, pedimos que ele seja realizado em .NET, Java ou NodeJS. | ||
|
||
### Como o meu projeto será avaliado? | ||
Os três prontos principais são os seguintes: | ||
- Ambiente: Como mencionado acima, é esperado que seja possível ter um ambiente com o projeto executando de maneira fácil e rápida. Qualquer instrução necessária para isso deve ser fornecida pelo desenvolvedor. Esse será o primeiro ponto a ser avaliado. | ||
- API: O ponto principal do teste é a implementação da API, exatamente como descrita no arquivo api.yaml. Os diferentes erros estão fornecidos como exemplos na documentação da API. Nenhum dos cenários descritos como erro na documentação deve ser permitido pelo serviço. | ||
- Testes: É esperado que, ao mínimo, sejam criados testes unitários para as funcionalidades implementadas no desafio. | ||
Além disso, naturalmente, o código do desafio será avaliado. | ||
|
||
### Durante a implementação, encontrei um cenário que não está 100% claro para mim como deve ser implementado. Como devo proceder? | ||
Ao encontrar alguma situação além do que está descrito na documentação da API, faça da maneira que, na sua visão, faz mais sentido para o contexto de uma API de controle de folha de ponto. | ||
|
||
### Terminei a implementação da API. É necessário fazer mais alguma coisa? | ||
Não há nenhum outro requisito fixo além dos especificados na documentação da API e nesse documento. Porém, pedimos que, dentro do prazo estabelecido, o desafio seja entregue da maneira mais completa possível. Será avaliado o que o candidato considera ser essencial para a entrega do projeto. | ||
|
||
### Terminei o desafio. Como faço a entrega? | ||
Envie-nos por favor um link com o repositório para que possamos dar uma olhada no código. 😉 | ||
If no `DATABASE_URI` is provided a temporary in-memory mongodb instance is created. |
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,40 @@ | ||
require("dotenv").config(); | ||
const { MongoMemoryServer } = require("mongodb-memory-server"); | ||
const express = require("express"); | ||
const mongoose = require("mongoose"); | ||
const bodyParser = require("body-parser"); | ||
const routes = require("./routes"); | ||
|
||
const app = express(); | ||
const port = process.env.PORT || 80; | ||
|
||
const connectToMongoDB = async () => { | ||
if (process.env.DATABASE_URI) { | ||
return mongoose.connect(process.env.DATABASE_URI, { useNewUrlParser: true, useUnifiedTopology: true }); | ||
} else { | ||
const mongoServer = new MongoMemoryServer(); | ||
await mongoServer.start(); | ||
const mongoUri = await mongoServer.getUri(); | ||
return mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true }); | ||
} | ||
}; | ||
|
||
connectToMongoDB() | ||
.then(() => { | ||
console.log(`Connected to MongoDB in ${process.env.NODE_ENV} mode`); | ||
if (require.main === module) { | ||
app.listen(port, () => { | ||
console.log(`Server is running on port ${port}`); | ||
}); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error("Error connecting to MongoDB:", err.message); | ||
}); | ||
|
||
app.use(express.json()); | ||
app.use(bodyParser.json()); | ||
|
||
app.use("/", routes); | ||
|
||
module.exports = app; |
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,40 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
const BatidaSchema = new mongoose.Schema({ | ||
momento: { | ||
type: Date, | ||
required: true | ||
} | ||
}); | ||
|
||
const ExpedienteSchema = new mongoose.Schema({ | ||
dia: { | ||
type: String, | ||
validate: { | ||
validator: function (value) { | ||
return /^\d{4}-\d{2}-\d{2}$/.test(value); | ||
}, | ||
message: "{VALUE} must be in YYYY-MM-DD format" | ||
}, | ||
required: true | ||
}, | ||
horasTrabalhadas: { | ||
type: Number, | ||
validate: { | ||
validator: Number.isInteger, | ||
message: "{VALUE} is not an integer value" | ||
}, | ||
required: true | ||
}, | ||
batidas: [ | ||
{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "Batida" | ||
} | ||
] | ||
}); | ||
|
||
const Batida = mongoose.model("Batida", BatidaSchema); | ||
const Expediente = mongoose.model("Expediente", ExpedienteSchema); | ||
|
||
module.exports = { Batida, Expediente }; |
Oops, something went wrong.