mirror of
https://github.com/PeterMaquiran/tvone-api.git
synced 2026-04-23 18:05:50 +00:00
add seed and disable authtication for category
This commit is contained in:
Generated
+11807
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -20,7 +20,8 @@
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||
"seed": "ts-node prisma/seed.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^11.0.1",
|
||||
|
||||
Generated
-7555
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@ import { defineConfig, env } from 'prisma/config';
|
||||
export default defineConfig({
|
||||
schema: 'prisma/schema.prisma',
|
||||
migrations: {
|
||||
seed: 'ts-node prisma/seed.ts',
|
||||
path: 'prisma/migrations',
|
||||
},
|
||||
datasource: {
|
||||
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const data = [
|
||||
{
|
||||
name: 'Política',
|
||||
slug: 'politica',
|
||||
children: [
|
||||
{ name: 'Eleições', slug: 'eleicoes' },
|
||||
{ name: 'Governo', slug: 'governo' },
|
||||
{ name: 'Diplomacia', slug: 'diplomacia' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Mundo',
|
||||
slug: 'mundo',
|
||||
children: [
|
||||
{ name: 'Europa', slug: 'europa' },
|
||||
{ name: 'África', slug: 'africa' },
|
||||
{ name: 'Ásia', slug: 'asia' },
|
||||
{ name: 'Américas', slug: 'americas' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Negócios',
|
||||
slug: 'negocios',
|
||||
children: [
|
||||
{ name: 'Mercados', slug: 'mercados' },
|
||||
{ name: 'Startups', slug: 'startups' },
|
||||
{ name: 'Economia', slug: 'economia' },
|
||||
{ name: 'Cripto', slug: 'cripto' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Tecnologia',
|
||||
slug: 'tecnologia',
|
||||
children: [
|
||||
{ name: 'Inteligência Artificial', slug: 'inteligencia-artificial' },
|
||||
{ name: 'Gadgets', slug: 'gadgets' },
|
||||
{ name: 'Software', slug: 'software' },
|
||||
{ name: 'Cibersegurança', slug: 'ciberseguranca' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Esportes',
|
||||
slug: 'esportes',
|
||||
children: [
|
||||
{ name: 'Futebol', slug: 'futebol' },
|
||||
{ name: 'Basquete', slug: 'basquete' },
|
||||
{ name: 'Tênis', slug: 'tenis' },
|
||||
{ name: 'Fórmula 1', slug: 'formula-1' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Entretenimento',
|
||||
slug: 'entretenimento',
|
||||
children: [
|
||||
{ name: 'Filmes', slug: 'filmes' },
|
||||
{ name: 'Música', slug: 'musica' },
|
||||
{ name: 'Celebridades', slug: 'celebridades' },
|
||||
{ name: 'Séries de TV', slug: 'series-tv' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Saúde',
|
||||
slug: 'saude',
|
||||
children: [
|
||||
{ name: 'Medicina', slug: 'medicina' },
|
||||
{ name: 'Nutrição', slug: 'nutricao' },
|
||||
{ name: 'Saúde Mental', slug: 'saude-mental' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Ciência',
|
||||
slug: 'ciencia',
|
||||
children: [
|
||||
{ name: 'Espaço', slug: 'espaco' },
|
||||
{ name: 'Meio Ambiente', slug: 'meio-ambiente' },
|
||||
{ name: 'Física', slug: 'fisica' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Estilo de Vida',
|
||||
slug: 'estilo-de-vida',
|
||||
children: [
|
||||
{ name: 'Viagem', slug: 'viagem' },
|
||||
{ name: 'Comida', slug: 'comida' },
|
||||
{ name: 'Moda', slug: 'moda' },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
async function createCategory(node: any, parentId: string | null = null) {
|
||||
const category = await prisma.category.create({
|
||||
data: {
|
||||
name: node.name,
|
||||
slug: node.slug,
|
||||
parentId,
|
||||
},
|
||||
});
|
||||
|
||||
if (node.children?.length) {
|
||||
for (const child of node.children) {
|
||||
await createCategory(child, category.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('🌱 Seeding categories...');
|
||||
|
||||
for (const root of data) {
|
||||
await createCategory(root);
|
||||
}
|
||||
|
||||
console.log('✅ Categories seeded successfully');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
@@ -32,22 +32,22 @@ export class CategoriesController {
|
||||
return this.categoriesService.findAllFlat();
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN, UserRole.EDITOR)
|
||||
//@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
//@Roles(UserRole.ADMIN, UserRole.EDITOR)
|
||||
@Post()
|
||||
create(@Body() dto: CreateCategoryDto) {
|
||||
return this.categoriesService.create(dto);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN, UserRole.EDITOR)
|
||||
//@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
//@Roles(UserRole.ADMIN, UserRole.EDITOR)
|
||||
@Patch(':id')
|
||||
update(@Param('id', ParseUUIDPipe) id: string, @Body() dto: UpdateCategoryDto) {
|
||||
return this.categoriesService.update(id, dto);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN, UserRole.EDITOR)
|
||||
//@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
//@Roles(UserRole.ADMIN, UserRole.EDITOR)
|
||||
@Delete(':id')
|
||||
remove(@Param('id', ParseUUIDPipe) id: string) {
|
||||
return this.categoriesService.remove(id);
|
||||
|
||||
Reference in New Issue
Block a user