120 lines
3.4 KiB
JavaScript
120 lines
3.4 KiB
JavaScript
import _ from 'lodash';
|
|
import {
|
|
saveFromTemplate,
|
|
randomLocaleObject,
|
|
dateBetween,
|
|
person,
|
|
lorem,
|
|
} from './common.js';
|
|
|
|
const keys = {
|
|
designerid: 233,
|
|
name: '',
|
|
path: '',
|
|
username: '',
|
|
password: 'NULL',
|
|
co: '',
|
|
street: '',
|
|
zipcode: '',
|
|
city: '',
|
|
territory: 'SE',
|
|
phone: '',
|
|
email: '',
|
|
orgnr: '',
|
|
currency: 'SEK',
|
|
commission: 18,
|
|
commission_resale: 18,
|
|
balance: 0,
|
|
description: 'NULL',
|
|
comments: '',
|
|
status: 1,
|
|
inserted: '2019-06-25 12:18:27.781469+02',
|
|
updated: '2021-04-14 15:16:31.031097+02',
|
|
license_image: 'NULL',
|
|
type: 'NULL',
|
|
segmentation: 1,
|
|
visible_search: 1,
|
|
visible_list: 1,
|
|
visible_productpage: 1,
|
|
visible_designerpage: 1,
|
|
sort_desc: false,
|
|
no_follow: 0,
|
|
logotype: 'designers/xxx.jpg',
|
|
automatic_payout: 0,
|
|
pricepremium_wallpaper: 18,
|
|
pricepremium_canvas: 18,
|
|
pricepremium_poster: 18,
|
|
pricepremium_framed_print: 18,
|
|
wallpaper_image_id: 'NULL',
|
|
canvas_image_id: 'NULL',
|
|
poster_image_id: 'NULL',
|
|
framed_print_image_id: 'NULL',
|
|
};
|
|
|
|
const inserts = [];
|
|
|
|
const N = 10;
|
|
for (const id of [...Array(N + 1).keys()].slice(1)) {
|
|
const fp = person();
|
|
const updated = dateBetween(200101, 200301);
|
|
const lo = randomLocaleObject();
|
|
|
|
const key = Object.assign({}, keys, {
|
|
designerid: 'DEFAULT', // 10
|
|
name: `'${fp.firstName} ${fp.lastName}'`, // 100
|
|
path: `'${_.kebabCase(`${fp.firstName}-${fp.lastName}`)}'`, // 100
|
|
username: `'${_.kebabCase(`${fp.firstName}-${fp.lastName}`)}'`, // 100
|
|
co: `'${fp.job.company} ${lorem.generateWords(1)}'`, // 100
|
|
street: `'${fp.adress.street}'`, // 100
|
|
zipcode: `'${fp.adress.zip}'`, // 100
|
|
city: `'${fp.adress.city}'`,
|
|
territory: lo.country,
|
|
phone: `'${fp.contacts.phone}'`,
|
|
email: `'${fp.contacts.email}'`,
|
|
orgnr: `'123456-4321'`,
|
|
currency: lo.currency,
|
|
commission: 18,
|
|
commission_resale: 18,
|
|
balance: 0,
|
|
comments: `''`,
|
|
status: 1,
|
|
inserted: 'DEFAULT',
|
|
updated: `'${new Date(updated).toISOString()}'`, // 2021-04-15 08:07:14.322589+02
|
|
segmentation: 1,
|
|
visible_search: 1,
|
|
visible_list: 1,
|
|
visible_productpage: 1,
|
|
visible_designerpage: 1,
|
|
sort_desc: false,
|
|
no_follow: 0,
|
|
logotype: `'designers/${id}.jpg'`,
|
|
automatic_payout: 0,
|
|
pricepremium_wallpaper: 18,
|
|
pricepremium_canvas: 18,
|
|
pricepremium_poster: 18,
|
|
pricepremium_framed_print: 18,
|
|
});
|
|
|
|
// Since the graphql query for designers is
|
|
// sorted on name we force the second designer
|
|
// to to top of the name sort.
|
|
// This is because we insert order on designer with
|
|
// id = 2
|
|
if (id === 2) {
|
|
key.name = `'a'`;
|
|
}
|
|
|
|
const insertString = `INSERT INTO public.designers (designerid, name, path, username, password, co, street, zipcode, city, territory, phone, email, orgnr, currency, commission, commission_resale, balance, description, comments, status, inserted, updated, license_image, type, segmentation, visible_search, visible_list, visible_productpage, visible_designerpage, sort_desc, no_follow, logotype, automatic_payout, pricepremium_wallpaper, pricepremium_canvas, pricepremium_poster, pricepremium_framed_print, wallpaper_image_id, canvas_image_id, poster_image_id, framed_print_image_id) VALUES (${Object.values(
|
|
key,
|
|
).join(', ')});`;
|
|
|
|
inserts.push(insertString);
|
|
}
|
|
|
|
saveFromTemplate(
|
|
'templates/designers.sql',
|
|
'../db/data/designers.sql',
|
|
'{x}',
|
|
inserts.join('\n'),
|
|
);
|