Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/build-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build Backend

on:
push:
branches:
- main
- build
pull_request:
branches:
- main
- build

jobs:

build-backend:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/source_connector:latest
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ WORKDIR /app
COPY . .
#COPY ../utils ../utils
RUN npm install
COPY ./token.template.js ./token.js
CMD ["node", "index"]
14 changes: 12 additions & 2 deletions api/controllers/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const logger = require('percocologger')

module.exports = {



sync: async (req, res) => {
logger.info("Sync")
Expand All @@ -13,11 +13,21 @@ module.exports = {
notifyPath: async (req, res) => {
logger.info("Notification received")
try {
res.send(await service.notifyPath(req, res))
let response = await service.notifyPath(req, res)
if (typeof response == "string")
return res.send(response)
else
res.status(500).send(response?.toString() == "[object Object]" ? response : response.toString())
}
catch (error) {
logger.error(error)
res.status(500).send(error.toString() == "[object Object]" ? error : error.toString())
}
},

queue : async (req, res) => {
logger.info("Queue")
return await res.send(await service.queue())
}

}
6 changes: 4 additions & 2 deletions api/models/Datapoint.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const mongoose = require("mongoose");
const crypto = require("crypto");
const config = require("../../config")

// Funzione di utilità per pulire il nome della survey
const cleanSurveyName = (val) => {
Expand All @@ -17,7 +18,7 @@ const datapointSchema = new mongoose.Schema(
timestamp: { type: String, index: true },
dimensions: { type: Object },
value: Number,
dupl_hash: { type: String }, // Identificatore unico per evitare duplicati
dupl_hash: { type: String, unique : config.upsertRecords == true }, // Identificatore unico per evitare duplicati
},
{
strict: false,
Expand All @@ -37,11 +38,12 @@ datapointSchema.pre("save", function (next) {

// Funzione per generare l'hash unico (usata nell'inserimento massivo)
const generateHash = (doc) => {
return JSON.stringify(doc)
// Gestiamo sia se arriva come documento Mongoose sia come oggetto puro
const target = doc._doc || doc;

const dims = target.dimensions || [];
const sortedDims = [...dims].sort();
const sortedDims = [...dims].sort();//FIXME funziona solo con gli array, ci vorrebbe Object.entries()
const sortedKeys = sortedDims.join("|");

const s = cleanSurveyName(target.survey);
Expand Down
6 changes: 6 additions & 0 deletions api/models/Dimensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const mongoose = require("mongoose");

const dimensions
= new mongoose.Schema({}, { strict: false, versionKey: false });

module.exports = mongoose.model("dimensions", dimensions);
5 changes: 5 additions & 0 deletions api/models/Entity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const mongoose = require("mongoose");

const entity = new mongoose.Schema({}, { strict: false, versionKey: false })

module.exports = mongoose.model("entities", entity);
1 change: 1 addition & 0 deletions api/routes/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const { auth } = require("../middlewares/auth.js")

router.post(encodeURI("/orion/subscribe/:mapID"), auth, controller.notifyPath)
router.put(encodeURI("/query"), auth, controller.sync)
router.get(encodeURI("/queue"), auth, controller.queue)

module.exports = router
Loading
Loading