Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export için Scriptleri ekle #105

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ node_modules
node_modules/
.env
package-lock.json
.vscode
anonrig marked this conversation as resolved.
Show resolved Hide resolved
coverage
.DS_Store
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ localhost:8080/yardim?page=1&limit=1

Json Yolla
localhost:8080/yardim

- /models/yardimModel.js e bak
ÖRNEK JSON POSTU
* /models/yardimModel.js e bak
ÖRNEK JSON POSTU

```
{
Expand Down
10 changes: 3 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ const config = require("./config.js");
const cache = require("./cache.js");
const buildServer = require("./server/build.js");

const mongoose = require("mongoose");

const app = buildServer();

const Database = require("./utils/Database");

// DB connection
mongoose
.connect(config.mongoUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
Database.connect(app.log.info)
.then(() => {
cache.createCacheInstance();
app.log.info("Connected to DB...");
Expand Down
7,125 changes: 2,574 additions & 4,551 deletions package-lock.json

Large diffs are not rendered by default.

78 changes: 40 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
{
"name": "deprem-io-backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "npx nodemon --exec \"node index.js\"",
"test": "vitest run --coverage",
"lint": "rome check --apply-suggested .",
"format": "rome format --write ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/acikkaynak/deprem-io-backend.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/acikkaynak/deprem-io-backend/issues"
},
"homepage": "https://github.com/acikkaynak/deprem-io-backend#readme",
"dependencies": {
"@fastify/autoload": "^5.7.1",
"@fastify/cors": "^8.2.0",
"@fastify/swagger": "^8.3.1",
"@fastify/swagger-ui": "^1.3.0",
"dotenv": "^16.0.3",
"fastify": "^4.13.0",
"mongoose": "^6.9.1",
"node-cache": "^5.1.2"
},
"devDependencies": {
"@vitest/coverage-c8": "^0.28.4",
"nodemon": "^2.0.20",
"rome": "^11.0.0",
"vitest": "^0.28.4"
}
}
"name": "deprem-io-backend",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bu dosyanin indentation'ini neden degistirdik

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bunu ben de anlayamadım normalde Rome kullanmıyorum ama uyumlu olması için tüm gerekli ayarları yaptım yine de sorun oluyor

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

degisiklikleri eski haline alalim lutfen

"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "npx nodemon --exec \"node index.js\"",
"test": "vitest run --coverage",
"lint": "rome check --apply-suggested .",
"format": "rome format --write ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/acikkaynak/deprem-io-backend.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/acikkaynak/deprem-io-backend/issues"
},
"homepage": "https://github.com/acikkaynak/deprem-io-backend#readme",
"dependencies": {
"@fastify/autoload": "^5.7.1",
"@fastify/cors": "^8.2.0",
"@fastify/swagger": "^8.3.1",
"@fastify/swagger-ui": "^1.3.0",
"dotenv": "^16.0.3",
"fastify": "^4.13.0",
"mongoose": "^6.9.1",
"node-cache": "^5.1.2",
"objects-to-csv": "^1.3.6",
"request-ip": "^3.3.0"
},
"devDependencies": {
"@vitest/coverage-c8": "^0.28.4",
"nodemon": "^2.0.20",
"rome": "^11.0.0",
"vitest": "^0.28.4"
}
}
5 changes: 1 addition & 4 deletions routes/controllers/iletisim.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { checkConnection } = require("../utils");
const Iletisim = require("../../models/iletisimModel");
const check = new (require("../../lib/Check"))();
const Iletisim = require("../../models/iletisimModel");

module.exports = async function (fastifyInstance) {
fastifyInstance.post(
Expand All @@ -19,8 +18,6 @@ module.exports = async function (fastifyInstance) {
},
},
async function (req, res) {
await checkConnection(fastifyInstance);

const existingIletisim = await Iletisim.findOne({
adSoyad: req.body.adSoyad,
email: req.body.email,
Expand Down
11 changes: 4 additions & 7 deletions routes/controllers/yardim.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const cache = require("../../cache");
const check = new (require("../../lib/Check"))();
const { checkConnection } = require("../utils");

const Yardim = require("../../models/yardimModel");
const YardimKaydi = require("../../models/yardimKaydiModel");

Expand Down Expand Up @@ -29,6 +29,7 @@ module.exports = async function (fastifyInstance) {
description: "Yardim listesi",
},
},

async function (req, res) {
const { page, limit, yardimTipi } = req.query;
const startIndex = (page - 1) * limit;
Expand All @@ -40,7 +41,6 @@ module.exports = async function (fastifyInstance) {
return cache.getCache().get(cacheKey);
}

await checkConnection(fastifyInstance);
if (endIndex < (await Yardim.countDocuments().exec())) {
results.next = {
page: page + 1,
Expand Down Expand Up @@ -138,8 +138,6 @@ module.exports = async function (fastifyInstance) {
}
}

await checkConnection(fastifyInstance);

// check exist
const existingYardim = await Yardim.findOne({ adSoyad, adres });
if (existingYardim) {
Expand Down Expand Up @@ -185,14 +183,12 @@ module.exports = async function (fastifyInstance) {
);

fastifyInstance.get("/yardim/:id", async (req, res) => {
let data;

const cacheKey = `yardim_${req.params.id}`;

if (cache.getCache().has(cacheKey)) {
return cache.getCache().get(cacheKey);
}
await checkConnection(fastifyInstance);

let results = await Yardim.findById(req.params.id);
let yardimKaydi = await YardimKaydi.find({ postId: req.params.id });
try {
Expand Down Expand Up @@ -243,6 +239,7 @@ module.exports = async function (fastifyInstance) {
},
},
},

async (req, res) => {
const queryString = req.query.q || "";
const yardimDurumuQuery = req.query.yardimDurumu;
Expand Down
10 changes: 5 additions & 5 deletions routes/controllers/yardimEt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const cache = require("../../cache");
const check = new (require("../../lib/Check"))();
const { checkConnection } = require("../utils");

const YardimEt = require("../../models/yardimEtModel");

module.exports = async function (fastifyInstance) {
Expand Down Expand Up @@ -49,8 +49,6 @@ module.exports = async function (fastifyInstance) {
}
}

await checkConnection(fastifyInstance);

// check exist
const existingYardim = await YardimEt.findOne({ adSoyad, sehir });
if (existingYardim) {
Expand Down Expand Up @@ -110,6 +108,7 @@ module.exports = async function (fastifyInstance) {
},
},
},

async function (req, res) {
const { page, limit, yardimTipi, sehir, hedefSehir } = req.query;
const startIndex = (page - 1) * limit;
Expand All @@ -123,7 +122,6 @@ module.exports = async function (fastifyInstance) {
if (cache.getCache().has(cacheKey)) {
return cache.getCache().get(cacheKey);
}
await checkConnection(fastifyInstance);

if (endIndex < (await YardimEt.countDocuments().exec())) {
results.next = {
Expand Down Expand Up @@ -178,8 +176,9 @@ module.exports = async function (fastifyInstance) {
if (cache.getCache().has(cacheKey)) {
return cache.getCache().get(cacheKey);
}
await checkConnection(fastifyInstance);

const results = await YardimEt.findById(req.params.id);

results.telefon = results.telefon.replace(/.(?=.{4})/g, "*");
const yedekTelefonlar = results.yedekTelefonlar;
if (results.yedekTelefonlar) {
Expand Down Expand Up @@ -213,6 +212,7 @@ module.exports = async function (fastifyInstance) {
},
},
},

async (req, res) => {
const queryString = req.query.q;
const yardimDurumuQuery = req.query.yardimDurumu;
Expand Down
5 changes: 2 additions & 3 deletions routes/controllers/yardimKaydi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { checkConnection } = require("../utils");
const Yardim = require("../../models/yardimModel");
const check = new (require("../../lib/Check"))();

const Yardim = require("../../models/yardimModel");
const YardimKaydi = require("../../models/yardimKaydiModel");

module.exports = async function (fastifyInstance) {
Expand All @@ -23,7 +23,6 @@ module.exports = async function (fastifyInstance) {
},
},
async (req, res) => {
await checkConnection(fastifyInstance);
const existingYardimKaydi = await Yardim.findOne({
_id: req.body.postId,
});
Expand Down
13 changes: 0 additions & 13 deletions routes/utils.js

This file was deleted.

35 changes: 35 additions & 0 deletions scripts/ExportYardim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Database = require("../utils/Database");

const Yardim = require("../models/yardimModel");

const CsvExporter = require("../utils/CsvExporter");

// Datayı csv olarak export etmek için script
async function main() {
await Database.connect();

const select = [
"yardimTipi",
"adSoyad",
"telefon",
"yedekTelefonlar",
"email",
"adres",
"adresTarifi",
"acilDurum",
"kisiSayisi",
"yardimDurumu",
"fizikiDurum",
"googleMapLink",
"tweetLink",
"fields",
"ip",
"createdAt",
"updatedAt",
];

const docs = await Yardim.find({}).select(select).lean();
await CsvExporter(docs, select, `Yardım_Export_${Date.now()}.csv`);
}

main().then(console.log).catch(console.error);
28 changes: 28 additions & 0 deletions scripts/ExportYardimEt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const Database = require("../utils/Database");

const YardimEt = require("../models/yardimEtModel");

const CsvExporter = require("../utils/CsvExporter");

// Datayı csv olarak export etmek için script
async function main() {
await Database.connect();

const select = [
"ip",
"yardimTipi",
"adSoyad",
"telefon",
"sehir",
"hedefSehir",
"aciklama",
"createdAt",
"updatedAt",
"fields",
];

const docs = await YardimEt.find({}).select(select).lean();
await CsvExporter(docs, select, `Yardım_Et_Export_${Date.now()}.csv`);
}

main().then(console.log).catch(console.error);
17 changes: 17 additions & 0 deletions scripts/ExportYardimKaydi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const Database = require("../utils/Database");

const YardimKaydi = require("../models/yardimKaydiModel");

const CsvExporter = require("../utils/CsvExporter");

// Datayı csv olarak export etmek için script
async function main() {
await Database.connect();

const select = ["postId", "adSoyad", "telefon", "sonDurum", "email", "aciklama"];

const docs = await YardimKaydi.find({}).select(select).lean();
await CsvExporter(docs, select, `Yardım_Kaydi_Export_${Date.now()}.csv`);
}

main().then(console.log).catch(console.error);
38 changes: 0 additions & 38 deletions scripts/exportYardimEtCsv.js

This file was deleted.

Loading