#10 added fixtures fro each instance

parent 6342cb0f
......@@ -4,6 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"seed": "ts-node-dev --transpile-only src/fixtures.ts",
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
......@@ -35,4 +36,4 @@
"@types/mongoose-sequence": "^3.0.7",
"@types/multer": "^1.4.7"
}
}
}
\ No newline at end of file
*
!.gitignore
\ No newline at end of file
......@@ -3,6 +3,7 @@ import UserModel from '../models/user';
import {getErrorMessage} from '../utils/errors.util';
import * as TrackHistoryService from '../services/track.history';
import TrackModel from '../models/track';
import {CustomRequest} from '../middleware/auth';
export const authorize = async (req: Request, res: Response) => {
try {
......
import mongoose, {ObjectId, mongo} from 'mongoose';
import dotenv from 'dotenv';
import UserModel from './models/user';
import ArtistModel from './models/artist';
import AlbumModel from './models/album';
import TrackModel from './models/track';
dotenv.config();
mongoose.connect(process.env.MONGO_URL + '/MyPlayer');
const db = mongoose.connection;
db.once('open', async () => {
try {
await db.dropCollection('users');
await db.dropCollection('artists');
await db.dropCollection('albums');
await db.dropCollection('tracks');
} catch (e) {
console.log('Collections were not present, skipping drop...');
}
await UserModel.create(
{
username: 'alen',
password: '1',
},
{
username: 'danil',
password: '2',
}
);
const firstArtistId = new mongoose.Types.ObjectId();
const secondArtisId = new mongoose.Types.ObjectId();
await ArtistModel.create(
{
_id: firstArtistId,
info: 'Aubrey Drake Graham is a Canadian rapper and singer. An influential global figure in contemporary popular music, Drake has been credited for popularizing singing and R&B sensibilities in hip hop.',
name: 'Drake',
photo: 'drake.jpg',
},
{
_id: secondArtisId,
info: 'Marshall Bruce Mathers III, known professionally as Eminem, is an American rapper, songwriter, and record producer. He is credited with popularizing hip hop in middle America and is critically acclaimed as one of the greatest rappers of all time.',
name: 'Eminem',
photo: 'eminem.png',
}
);
const firstAlbumId = new mongoose.Types.ObjectId();
const secondAlbumId = new mongoose.Types.ObjectId();
const thirdAlbumId = new mongoose.Types.ObjectId();
await AlbumModel.create(
{
_id: firstAlbumId,
artist: firstArtistId,
image: 'album1.jpg',
year: 2001,
name: 'Room for Improvement',
},
{
_id: secondAlbumId,
artist: firstArtistId,
image: 'album2.jpg',
year: 2005,
name: 'Comeback Season',
},
{
_id: thirdAlbumId,
artist: secondArtisId,
image: 'album3.jpg',
year: 2011,
name: 'One fortune',
}
);
await TrackModel.create(
{
album: firstAlbumId,
duration: '2:56',
name: 'Predator',
},
{
album: secondAlbumId,
duration: '3:10',
name: 'Mommy',
}
);
db.close();
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment