forked from yoone/API
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { Seeder } from 'typeorm-extension';
|
|
import { DataSource } from 'typeorm';
|
|
import { Category } from '../../entity/category.entity';
|
|
|
|
export default class CategorySeeder implements Seeder {
|
|
public async run(
|
|
dataSource: DataSource,
|
|
): Promise<any> {
|
|
const repository = dataSource.getRepository(Category);
|
|
|
|
const categories = [
|
|
{
|
|
name: 'nicotine-pouches',
|
|
title: 'Nicotine Pouches',
|
|
titleCN: '尼古丁袋',
|
|
sort: 1
|
|
},
|
|
{
|
|
name: 'vape',
|
|
title: 'vape',
|
|
titleCN: '电子烟',
|
|
sort: 2
|
|
},
|
|
{
|
|
name: 'pouches-can',
|
|
title: 'Pouches Can',
|
|
titleCN: '口含烟盒',
|
|
sort: 3
|
|
},
|
|
];
|
|
|
|
for (const cat of categories) {
|
|
const existing = await repository.findOne({ where: { name: cat.name } });
|
|
if (!existing) {
|
|
await repository.save(cat);
|
|
}
|
|
}
|
|
}
|
|
}
|