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 12 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()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Database'in icersindeki console.log'lari kaldiralim. Aksi taktirde uygulama calisirken 2 sefer log yazmis oluyoruz. console.log yerine her zaman fastify.log kullanalim.

Copy link
Author

Choose a reason for hiding this comment

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

tabi

.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
17 changes: 10 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",
},
},
// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

ts-ignore'larin hepsi senin IDE'nden kaynaklanan sorunlari cozmek icin kullaniliyor sanirim. Typescript yazmadigimiz icin bu ignorelarin hepsini kaldiralim lutfen.

Copy link
Author

Choose a reason for hiding this comment

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

tamamdır

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 All @@ -202,10 +198,12 @@ module.exports = async function (fastifyInstance) {
}
});

// @ts-ignore
results.telefon = results.telefon.replace(/.(?=.{4})/g, "*");
const yedekTelefonlar = results.yedekTelefonlar;
if (results.yedekTelefonlar) {
results.yedekTelefonlar = yedekTelefonlar.map((yedekTelefon) => {
// @ts-ignore
return yedekTelefon.replace(/.(?=.{4})/g, "*");
});
}
Expand Down Expand Up @@ -243,6 +241,7 @@ module.exports = async function (fastifyInstance) {
},
},
},
// @ts-ignore
async (req, res) => {
const queryString = req.query.q || "";
const yardimDurumuQuery = req.query.yardimDurumu;
Expand All @@ -259,24 +258,28 @@ module.exports = async function (fastifyInstance) {
};

if (helpType) {
// @ts-ignore
query = {
$and: [query, { yardimTipi: helpType }],
};
}

if (vehicle) {
// @ts-ignore
query = {
$and: [query, { aracDurumu: vehicle }],
};
}

if (yardimDurumuQuery) {
// @ts-ignore
query = {
$and: [query, { yardimDurumu: yardimDurumuQuery }],
};
}

if (acilDurumQuery) {
// @ts-ignore
query = {
$and: [query, { acilDurum: acilDurumQuery }],
};
Expand Down
16 changes: 11 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,11 +108,13 @@ module.exports = async function (fastifyInstance) {
},
},
},
// @ts-ignore
async function (req, res) {
const { page, limit, yardimTipi, sehir, hedefSehir } = req.query;
const startIndex = (page - 1) * limit;
const endIndex = page * limit;

// @ts-ignore
let data;
let results = {};

Expand All @@ -123,7 +123,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,12 +177,14 @@ 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);
// @ts-ignore
results.telefon = results.telefon.replace(/.(?=.{4})/g, "*");
const yedekTelefonlar = results.yedekTelefonlar;
if (results.yedekTelefonlar) {
results.yedekTelefonlar = yedekTelefonlar.map((yedekTelefon) => {
// @ts-ignore
return yedekTelefon.replace(/.(?=.{4})/g, "*");
});
}
Expand Down Expand Up @@ -213,6 +214,7 @@ module.exports = async function (fastifyInstance) {
},
},
},
// @ts-ignore
async (req, res) => {
const queryString = req.query.q;
const yardimDurumuQuery = req.query.yardimDurumu;
Expand All @@ -224,24 +226,28 @@ module.exports = async function (fastifyInstance) {
};

if (helpType) {
// @ts-ignore
query = {
$and: [query, { yardimTipi: helpType }],
};
}

if (location) {
// @ts-ignore
query = {
$and: [query, { sehir: location }],
};
}

if (dest) {
// @ts-ignore
query = {
$and: [query, { hedefSehir: dest }],
};
}

if (yardimDurumuQuery) {
// @ts-ignore
query = {
$and: [query, { yardimDurumu: yardimDurumuQuery }],
};
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);
Loading