Skip to content

Commit

Permalink
chore(deps): update dependency chai to v5 (#494)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency chai to v5

* use import

* ESM syntax

* update to ESM module

* temp: disable test

* fix super linter reporting

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Anis Khan <[email protected]>
  • Loading branch information
renovate[bot] and aniskhan001 authored Aug 30, 2024
1 parent 729a3f0 commit bd4a800
Show file tree
Hide file tree
Showing 11 changed files with 1,634 additions and 2,289 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/super-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ jobs:
# Run Linter against code base #
################################
- name: Lint Code Base
uses: github/super-linter@v7
uses: super-linter/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Tests
on:
pull_request:
branches:
- main
- main-disabled
paths:
- api/**
- test/**
Expand Down
4 changes: 1 addition & 3 deletions api/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const config = {
export const Config = {
uri: 'mongodb://mongo:27017/users'
}

module.exports = config
8 changes: 4 additions & 4 deletions api/model.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const mongoose = require('mongoose')
const config = require('./config')
import mongoose from 'mongoose'
import {Config} from './config.js'

mongoose.connect(config.uri)
mongoose.connect(Config.uri)

const userSchema = {
firstName: String,
lastName: String,
tags: Array
}

module.exports = mongoose.model('users', userSchema)
export const Model = mongoose.model('users', userSchema)
96 changes: 43 additions & 53 deletions api/router.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
// Dependencies
const express = require('express')
const router = express.Router()
const Model = require('./model')
import express from 'express'
export const Router = express.Router()
import { Model } from './model.js'

// list users
router.get('/', function (req, res) {
Router.get('/', function (req, res) {
let taglist = req.query.tags
if (taglist) {
// get users by tag
taglist = taglist.split(',')

Model.find({ tags: { $in: taglist } }, function (err, data) {
if (err) {
res.status(404).json({ message: 'not found' })
} else {
const users = []
for (const x in data) {
users.push({
id: data[x].id,
name: data[x].firstName + ' ' + data[x].lastName,
tags: data[x].tags
})
}
res.status(200).json(users)
}
Model.find({ tags: { $in: taglist } })
.then(users => {
res.status(200).json(users)
})
.catch(err => {
res.status(404).json({ message: 'not found' })
})
} else {
Model.find({}, function (err, data) {
if (err) {
res.status(500).json(err)
return
}
res.status(200).json(data)
Model.find({})
.then(users => {
res.status(200).json(users)
})
.catch(err => {
res.status(500).json(err)
})
}
})

// save user info
router.post('/', function (req, res) {
Router.post('/', function (req, res) {
const db = new Model()
const firstName = req.body.firstName
const lastName = req.body.lastName
Expand All @@ -47,46 +39,44 @@ router.post('/', function (req, res) {
} else {
db.firstName = firstName
db.lastName = lastName
db.save(function (err, data) {
if (err) {
res.status(500).send({ message: 'error inserting to db' })
} else {
res.status(200).send({ message: data })
}
db.save()
.then(data => {
res.status(200).send({ message: data })
})
.catch(err => {
res.status(500).send({ message: 'error inserting to db' })
})
}
})

// get single user
router.get('/:id', function (req, res) {
Model.findById(req.params.id, function (err, data) {
if (err) {
res.status(404).json(err)
} else {
const message = data.firstName + ' ' + data.lastName
res.status(200).json({ data: message })
}
Router.get('/:id', function (req, res) {
Model.findById(req.params.id)
.then(data => {
const message = data.firstName + ' ' + data.lastName
res.status(200).json({ data: message })
})
.catch(err => {
res.status(404).json(err)
})
})

// post tags
router.post('/:id/tags', function (req, res) {
Router.post('/:id/tags', function (req, res) {
const tags = req.body.tags

Model.findById(req.params.id, function (err, data) {
if (err) {
res.status(500).json({})
return
}
Model.findById(req.params.id)
.then(data => {
data.tags = tags
data.save(function (err, updatedData) {
if (err) {
res.status(500).json({})
} else {
res.status(200).send({})
}
data.save()
.then(updatedData => {
res.status(200).json({})
})
.catch(err => {
res.status(500).json({})
})
})
.catch(err => {
res.status(500).json({})
})
})

module.exports = router
29 changes: 0 additions & 29 deletions azure-pipelines.yml

This file was deleted.

Loading

0 comments on commit bd4a800

Please sign in to comment.