refactor: use tabs instead of spaces

This commit is contained in:
Sonny
2024-10-07 01:33:59 +02:00
parent f425decf2c
commit eea9732100
197 changed files with 5206 additions and 5209 deletions

View File

@@ -5,36 +5,36 @@ import { BaseSeeder } from '@adonisjs/lucid/seeders';
import { faker } from '@faker-js/faker';
export default class extends BaseSeeder {
static environment = ['development', 'testing'];
static environment = ['development', 'testing'];
async run() {
const users = await getUserIds();
async run() {
const users = await getUserIds();
const collections = faker.helpers.multiple(
() => createRandomCollection(users),
{
count: 50,
}
);
await Collection.createMany(collections);
}
const collections = faker.helpers.multiple(
() => createRandomCollection(users),
{
count: 50,
}
);
await Collection.createMany(collections);
}
}
export async function getUserIds() {
const users = await User.all();
return users.map(({ id }) => id);
const users = await User.all();
return users.map(({ id }) => id);
}
let collectionId = 0;
function createRandomCollection(userIds: User['id'][]) {
const authorId = faker.helpers.arrayElements(userIds, 1).at(0);
collectionId++;
return {
id: collectionId,
name: faker.string.alphanumeric({ length: { min: 5, max: 25 } }),
description: faker.string.alphanumeric({ length: { min: 0, max: 254 } }),
visibility: Visibility.PRIVATE,
nextId: collectionId + 1,
authorId,
};
const authorId = faker.helpers.arrayElements(userIds, 1).at(0);
collectionId++;
return {
id: collectionId,
name: faker.string.alphanumeric({ length: { min: 5, max: 25 } }),
description: faker.string.alphanumeric({ length: { min: 0, max: 254 } }),
visibility: Visibility.PRIVATE,
nextId: collectionId + 1,
authorId,
};
}

View File

@@ -6,41 +6,41 @@ import { BaseSeeder } from '@adonisjs/lucid/seeders';
import { faker } from '@faker-js/faker';
export default class extends BaseSeeder {
static environment = ['development', 'testing'];
static environment = ['development', 'testing'];
async run() {
const users = await getUserIds();
async run() {
const users = await getUserIds();
const links = await Promise.all(
faker.helpers.multiple(async () => createRandomLink(users), {
count: 500,
})
);
await Link.createMany(links.filter((a) => typeof a !== 'undefined') as any);
}
const links = await Promise.all(
faker.helpers.multiple(async () => createRandomLink(users), {
count: 500,
})
);
await Link.createMany(links.filter((a) => typeof a !== 'undefined') as any);
}
}
async function getCollectionIds(authorId: User['id']) {
const collection = await Collection.findManyBy('author_id', authorId);
return collection.map(({ id }) => id);
const collection = await Collection.findManyBy('author_id', authorId);
return collection.map(({ id }) => id);
}
async function createRandomLink(userIds: User['id'][]) {
const authorId = faker.helpers.arrayElements(userIds, 1).at(0)!;
const collections = await getCollectionIds(authorId);
const authorId = faker.helpers.arrayElements(userIds, 1).at(0)!;
const collections = await getCollectionIds(authorId);
const collectionId = faker.helpers.arrayElements(collections, 1).at(0);
if (!collectionId) {
return undefined;
}
const collectionId = faker.helpers.arrayElements(collections, 1).at(0);
if (!collectionId) {
return undefined;
}
return {
id: faker.string.uuid(),
name: faker.string.alphanumeric({ length: { min: 5, max: 25 } }),
description: faker.string.alphanumeric({ length: { min: 0, max: 254 } }),
url: faker.internet.url(),
favorite: faker.number.int({ min: 0, max: 1 }),
authorId,
collectionId,
};
return {
id: faker.string.uuid(),
name: faker.string.alphanumeric({ length: { min: 5, max: 25 } }),
description: faker.string.alphanumeric({ length: { min: 0, max: 254 } }),
url: faker.internet.url(),
favorite: faker.number.int({ min: 0, max: 1 }),
authorId,
collectionId,
};
}

View File

@@ -3,31 +3,31 @@ import logger from '@adonisjs/core/services/logger';
import { BaseSeeder } from '@adonisjs/lucid/seeders';
export default class IndexSeeder extends BaseSeeder {
private async seed(Seeder: { default: typeof BaseSeeder }) {
/**
* Do not run when not in a environment specified in Seeder
*/
if (
!Seeder.default.environment ||
(!Seeder.default.environment.includes('development') && app.inDev) ||
(!Seeder.default.environment.includes('testing') && app.inTest) ||
(!Seeder.default.environment.includes('production') && app.inProduction)
) {
return;
}
private async seed(Seeder: { default: typeof BaseSeeder }) {
/**
* Do not run when not in a environment specified in Seeder
*/
if (
!Seeder.default.environment ||
(!Seeder.default.environment.includes('development') && app.inDev) ||
(!Seeder.default.environment.includes('testing') && app.inTest) ||
(!Seeder.default.environment.includes('production') && app.inProduction)
) {
return;
}
await new Seeder.default(this.client).run();
}
await new Seeder.default(this.client).run();
}
async run() {
logger.info('Start user seed');
await this.seed(await import('#database/seeders/user_seeder'));
logger.info('User seed done');
logger.info('Collection user seed');
await this.seed(await import('#database/seeders/collection_seeder'));
logger.info('Collection seed done');
logger.info('Link user seed');
await this.seed(await import('#database/seeders/link_seeder'));
logger.info('Link seed done');
}
async run() {
logger.info('Start user seed');
await this.seed(await import('#database/seeders/user_seeder'));
logger.info('User seed done');
logger.info('Collection user seed');
await this.seed(await import('#database/seeders/collection_seeder'));
logger.info('Collection seed done');
logger.info('Link user seed');
await this.seed(await import('#database/seeders/link_seeder'));
logger.info('Link seed done');
}
}

View File

@@ -4,26 +4,26 @@ import { BaseSeeder } from '@adonisjs/lucid/seeders';
import { faker } from '@faker-js/faker';
export default class extends BaseSeeder {
static environment = ['development', 'testing'];
static environment = ['development', 'testing'];
async run() {
const users = faker.helpers.multiple(createRandomUser, {
count: 25,
});
await User.createMany(users);
}
async run() {
const users = faker.helpers.multiple(createRandomUser, {
count: 25,
});
await User.createMany(users);
}
}
export function createRandomUser() {
return {
id: faker.number.int(),
email: faker.internet.email(),
name: faker.internet.userName(),
nickName: faker.internet.displayName(),
avatarUrl: faker.image.avatar(),
isAdmin: false,
providerId: faker.number.int(),
providerType: 'google' as const,
token: {} as GoogleToken,
};
return {
id: faker.number.int(),
email: faker.internet.email(),
name: faker.internet.userName(),
nickName: faker.internet.displayName(),
avatarUrl: faker.image.avatar(),
isAdmin: false,
providerId: faker.number.int(),
providerType: 'google' as const,
token: {} as GoogleToken,
};
}