-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(uploads): add purge script example ✨
- Loading branch information
1 parent
6c1fe29
commit 363cd28
Showing
2 changed files
with
70 additions
and
0 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
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,31 @@ | ||
/** | ||
* Module dependencies | ||
*/ | ||
const chalk = require('chalk'); | ||
const path = require('path'); | ||
|
||
const mongooseService = require(path.resolve('./lib/services/mongoose')); | ||
|
||
/** | ||
* Work | ||
*/ | ||
|
||
const purge = async () => { | ||
try { | ||
await mongooseService.connect(); | ||
await mongooseService.loadModels(); | ||
|
||
const uploadRepository = require(path.resolve('./modules/uploads/repositories/uploads.repository')); | ||
const result = await uploadRepository.purge('avatar', 'users', 'avatar'); | ||
console.log(chalk.bold.blue(`Uploads purged ${result.deletedCount} avatar`)); | ||
} catch (err) { | ||
console.log(chalk.bold.red(`Error ${err}`)); | ||
} | ||
|
||
setTimeout(() => { | ||
console.log(chalk.green('Finish purge of uploads in mongoDB')); | ||
process.exit(0); | ||
}, 1000); | ||
}; | ||
|
||
purge(); |