Skip to content

Commit 5b18cdc

Browse files
added a bunch of seeds
1 parent 9549f3c commit 5b18cdc

File tree

10 files changed

+545
-1
lines changed

10 files changed

+545
-1
lines changed

app/Exceptions/Handler.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
const BaseExceptionHandler = use('BaseExceptionHandler');
4+
5+
/**
6+
* This class handles all exceptions thrown during
7+
* the HTTP request lifecycle.
8+
*
9+
* @class ExceptionHandler
10+
*/
11+
class ExceptionHandler extends BaseExceptionHandler {
12+
/**
13+
* Handle exception thrown during the HTTP lifecycle
14+
*
15+
* @method handle
16+
*
17+
* @param {Object} error
18+
* @param {Object} options.request
19+
* @param {Object} options.response
20+
*
21+
* @return {void}
22+
*/
23+
async handle(error, { request, response }) {
24+
if (error.code === 'E_INVALID_SESSION') {
25+
return response.redirect('/login');
26+
}
27+
//handled by parent
28+
return super.hanlde(...arguments);
29+
response.status(error.status).send(error.message);
30+
}
31+
32+
/**
33+
* Report exception for logging or debugging.
34+
*
35+
* @method report
36+
*
37+
* @param {Object} error
38+
* @param {Object} options.request
39+
*
40+
* @return {void}
41+
*/
42+
async report(error, { request }) {}
43+
}
44+
45+
module.exports = ExceptionHandler;

database/migrations/1550249369319_create_addresses_schema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ class CreateAddressesSchema extends Schema {
1111
address VARCHAR(100) NOT NULL,
1212
address_2 VARCHAR(100),
1313
city VARCHAR(60) NOT NULL,
14+
state VARCHAR(2) NOT NULL,
1415
country VARCHAR(3) NOT NULL,
1516
zipcode VARCHAR(5) NOT NULL,
17+
address_type VARCHAR(40) NOT NULL,
1618
user_id INT UNSIGNED NOT NULL,
1719
FOREIGN KEY(user_id) REFERENCES users(id),
1820
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

database/seeds/1BrandSeeder.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
const Database = use('Database');
3+
/*
4+
|--------------------------------------------------------------------------
5+
| BrandSeeder
6+
|--------------------------------------------------------------------------
7+
|
8+
| Make use of the Factory instance to seed database with dummy data or
9+
| make use of Lucid models directly.
10+
|
11+
*/
12+
13+
/** @type {import('@adonisjs/lucid/src/Factory')} */
14+
const Factory = use('Factory');
15+
16+
class BrandSeeder {
17+
async run() {
18+
try {
19+
const brand1 = await Database.raw(`
20+
INSERT INTO freshgear.brands (title)
21+
Values("Nike")
22+
`);
23+
console.log(`added Nike to Brands Table`);
24+
} catch (error) {
25+
console.log(error);
26+
}
27+
try {
28+
const brand2 = await Database.raw(`
29+
INSERT INTO freshgear.brands (title)
30+
Values("Adidas")
31+
`);
32+
console.log(`added Adidas to Brands Table`);
33+
} catch (error) {
34+
console.log(error);
35+
}
36+
try {
37+
const brand3 = await Database.raw(`
38+
INSERT INTO freshgear.brands (title)
39+
Values("Converse")
40+
`);
41+
console.log(`added Converse to Brands Table`);
42+
} catch (error) {
43+
console.log(error);
44+
}
45+
try {
46+
const brand4 = await Database.raw(`
47+
INSERT INTO freshgear.brands (title)
48+
Values("Reebok")
49+
`);
50+
console.log(`added Reebok to Brands Table`);
51+
} catch (error) {
52+
console.log(error);
53+
}
54+
try {
55+
const brand5 = await Database.raw(`
56+
INSERT INTO freshgear.brands (title)
57+
Values("Jordan")
58+
`);
59+
console.log(`added Jordan to Brands Table`);
60+
} catch (error) {
61+
console.log(error);
62+
}
63+
}
64+
}
65+
66+
module.exports = BrandSeeder;

database/seeds/2CategorySeeder.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
const Database = use('Database');
3+
/*
4+
|--------------------------------------------------------------------------
5+
| CategorySeeder
6+
|--------------------------------------------------------------------------
7+
|
8+
| Make use of the Factory instance to seed database with dummy data or
9+
| make use of Lucid models directly.
10+
|
11+
*/
12+
13+
/** @type {import('@adonisjs/lucid/src/Factory')} */
14+
const Factory = use('Factory');
15+
16+
class CategorySeeder {
17+
async run() {
18+
try {
19+
const category1 = await Database.raw(`
20+
INSERT INTO freshgear.categories (title)
21+
Values("Male")
22+
`);
23+
console.log(`added Male to Categories Table`);
24+
} catch (error) {
25+
console.log(error);
26+
}
27+
try {
28+
const category2 = await Database.raw(`
29+
INSERT INTO freshgear.categories (title)
30+
Values("Female")
31+
`);
32+
console.log(`added Female to Categories Table`);
33+
} catch (error) {
34+
console.log(error);
35+
}
36+
}
37+
}
38+
39+
module.exports = CategorySeeder;

database/seeds/3RoleSeeder.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
const Database = use('Database');
3+
/*
4+
|--------------------------------------------------------------------------
5+
| RoleSeeder
6+
|--------------------------------------------------------------------------
7+
|
8+
| Make use of the Factory instance to seed database with dummy data or
9+
| make use of Lucid models directly.
10+
|
11+
*/
12+
13+
/** @type {import('@adonisjs/lucid/src/Factory')} */
14+
const Factory = use('Factory');
15+
16+
class RoleSeeder {
17+
async run() {
18+
try {
19+
const customer = await Database.raw(`
20+
INSERT INTO freshgear.roles (title)
21+
Values("customer")
22+
`);
23+
console.log(`added Customer to Roles Table`);
24+
} catch (error) {
25+
console.log(error);
26+
}
27+
try {
28+
const service = await Database.raw(`
29+
INSERT INTO freshgear.roles (title)
30+
Values("service")
31+
`);
32+
console.log(`added Service to Roles Table`);
33+
} catch (error) {
34+
console.log(error);
35+
}
36+
try {
37+
const admin = await Database.raw(`
38+
INSERT INTO freshgear.roles (title)
39+
Values("admin")
40+
`);
41+
console.log(`added Admin to Roles Table`);
42+
} catch (error) {
43+
console.log(error);
44+
}
45+
}
46+
}
47+
48+
module.exports = RoleSeeder;

database/seeds/4UserSeeder.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'use strict';
2+
const Database = use('Database');
3+
const Hash = use('Hash');
4+
/*
5+
|--------------------------------------------------------------------------
6+
| UserSeeder
7+
|--------------------------------------------------------------------------
8+
|
9+
| Make use of the Factory instance to seed database with dummy data or
10+
| make use of Lucid models directly.
11+
|
12+
*/
13+
14+
/** @type {import('@adonisjs/lucid/src/Factory')} */
15+
const Factory = use('Factory');
16+
17+
class UserSeeder {
18+
async run() {
19+
let password = await Hash.make('test123');
20+
try {
21+
const user1 = await Database.raw(`
22+
INSERT INTO freshgear.users (username, email, password, f_name, l_name)
23+
Values("customer1", "customer1@gmail.com", "${password}", "John", "Smith")
24+
`);
25+
console.log(`added customer1 to database`);
26+
} catch (error) {
27+
console.log(error);
28+
}
29+
try {
30+
const user2 = await Database.raw(`
31+
INSERT INTO freshgear.users (username, email, password, f_name, l_name)
32+
Values("customer2", "customer2@gmail.com", "${password}", "Jane", "Doe")
33+
`);
34+
console.log(`added customer2 to database`);
35+
} catch (error) {
36+
console.log(error);
37+
}
38+
try {
39+
const user3 = await Database.raw(`
40+
INSERT INTO freshgear.users (username, email, password, f_name, l_name)
41+
Values("customer3", "customer3@gmail.com", "${password}", "Raul", "Dominges")
42+
`);
43+
console.log(`added customer3 to database`);
44+
} catch (error) {
45+
console.log(error);
46+
}
47+
try {
48+
const user4 = await Database.raw(`
49+
INSERT INTO freshgear.users (username, email, password, f_name, l_name)
50+
Values("service1", "service1@gmail.com", "${password}", "Cindy", "McGregor")
51+
`);
52+
console.log(`added service1 to database`);
53+
} catch (error) {
54+
console.log(error);
55+
}
56+
try {
57+
const user5 = await Database.raw(`
58+
INSERT INTO freshgear.users (username, email, password, f_name, l_name)
59+
Values("admin1", "admin1@gmail.com", "${password}", "Billy", "Dragon")
60+
`);
61+
console.log(`added admin1 to database`);
62+
} catch (error) {
63+
console.log(error);
64+
}
65+
}
66+
}
67+
68+
module.exports = UserSeeder;

database/seeds/5RoleUserSeeder.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
const Database = use('Database');
3+
/*
4+
|--------------------------------------------------------------------------
5+
| RoleUserSeeder
6+
|--------------------------------------------------------------------------
7+
|
8+
| Make use of the Factory instance to seed database with dummy data or
9+
| make use of Lucid models directly.
10+
|
11+
*/
12+
13+
/** @type {import('@adonisjs/lucid/src/Factory')} */
14+
const Factory = use('Factory');
15+
16+
class RoleUserSeeder {
17+
async run() {
18+
try {
19+
const customer = await Database.raw(`
20+
INSERT INTO freshgear.role_user (role_id, user_id)
21+
Values(1,1)
22+
`);
23+
} catch (error) {
24+
console.log(error);
25+
}
26+
try {
27+
const customer = await Database.raw(`
28+
INSERT INTO freshgear.role_user (role_id, user_id)
29+
Values(1,2)
30+
`);
31+
} catch (error) {
32+
console.log(error);
33+
}
34+
try {
35+
const customer = await Database.raw(`
36+
INSERT INTO freshgear.role_user (role_id, user_id)
37+
Values(1,3)
38+
`);
39+
} catch (error) {
40+
console.log(error);
41+
}
42+
try {
43+
const customer = await Database.raw(`
44+
INSERT INTO freshgear.role_user (role_id, user_id)
45+
Values(2,4)
46+
`);
47+
} catch (error) {
48+
console.log(error);
49+
}
50+
try {
51+
const customer = await Database.raw(`
52+
INSERT INTO freshgear.role_user (role_id, user_id)
53+
Values(3,5)
54+
`);
55+
} catch (error) {
56+
console.log(error);
57+
}
58+
console.log(`added roles to 5 users on Role_User Table`);
59+
}
60+
}
61+
62+
module.exports = RoleUserSeeder;

0 commit comments

Comments
 (0)