@newt-app/templates 0.21.1 → 0.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +41 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10610,18 +10610,19 @@ const columns = ['id', 'title', 'done', 'createdAt'] as const;
|
|
|
10610
10610
|
|
|
10611
10611
|
@Injectable()
|
|
10612
10612
|
export class TodosService {
|
|
10613
|
-
async findAll(): Promise<Todo[]> {
|
|
10613
|
+
async findAll(userId: string): Promise<Todo[]> {
|
|
10614
10614
|
const rows = await db
|
|
10615
10615
|
.selectFrom('todo')
|
|
10616
10616
|
.select(columns)
|
|
10617
|
+
.where('userId', '=', userId)
|
|
10617
10618
|
.orderBy('createdAt desc')
|
|
10618
10619
|
.execute();
|
|
10619
10620
|
return rows.map((row) => ({ ...row, done: Boolean(row.done) }));
|
|
10620
10621
|
}
|
|
10621
10622
|
|
|
10622
|
-
async create(title: string): Promise<Todo> {
|
|
10623
|
+
async create(userId: string, title: string): Promise<Todo> {
|
|
10623
10624
|
const id = randomUUID();
|
|
10624
|
-
await db.insertInto('todo').values({ id, title }).execute();
|
|
10625
|
+
await db.insertInto('todo').values({ id, userId, title }).execute();
|
|
10625
10626
|
const row = await db
|
|
10626
10627
|
.selectFrom('todo')
|
|
10627
10628
|
.select(columns)
|
|
@@ -10630,17 +10631,19 @@ export class TodosService {
|
|
|
10630
10631
|
return { ...row, done: Boolean(row.done) };
|
|
10631
10632
|
}
|
|
10632
10633
|
|
|
10633
|
-
async toggle(id: string): Promise<Todo> {
|
|
10634
|
+
async toggle(userId: string, id: string): Promise<Todo> {
|
|
10634
10635
|
const current = await db
|
|
10635
10636
|
.selectFrom('todo')
|
|
10636
10637
|
.select('done')
|
|
10637
10638
|
.where('id', '=', id)
|
|
10639
|
+
.where('userId', '=', userId)
|
|
10638
10640
|
.executeTakeFirst();
|
|
10639
10641
|
if (!current) throw new NotFoundException('Todo ' + id + ' not found');
|
|
10640
10642
|
await db
|
|
10641
10643
|
.updateTable('todo')
|
|
10642
10644
|
.set({ done: current.done ? 0 : 1 })
|
|
10643
10645
|
.where('id', '=', id)
|
|
10646
|
+
.where('userId', '=', userId)
|
|
10644
10647
|
.execute();
|
|
10645
10648
|
const row = await db
|
|
10646
10649
|
.selectFrom('todo')
|
|
@@ -10650,10 +10653,11 @@ export class TodosService {
|
|
|
10650
10653
|
return { ...row, done: Boolean(row.done) };
|
|
10651
10654
|
}
|
|
10652
10655
|
|
|
10653
|
-
async remove(id: string): Promise<void> {
|
|
10656
|
+
async remove(userId: string, id: string): Promise<void> {
|
|
10654
10657
|
const result = await db
|
|
10655
10658
|
.deleteFrom('todo')
|
|
10656
10659
|
.where('id', '=', id)
|
|
10660
|
+
.where('userId', '=', userId)
|
|
10657
10661
|
.executeTakeFirst();
|
|
10658
10662
|
if (!result.numDeletedRows) {
|
|
10659
10663
|
throw new NotFoundException('Todo ' + id + ' not found');
|
|
@@ -10692,6 +10696,7 @@ var db_schema_default = {
|
|
|
10692
10696
|
|
|
10693
10697
|
export interface TodoTable {
|
|
10694
10698
|
id: string;
|
|
10699
|
+
userId: string;
|
|
10695
10700
|
title: string;
|
|
10696
10701
|
done: Generated<number>;
|
|
10697
10702
|
createdAt: Generated<string>;
|
|
@@ -10711,6 +10716,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|
|
10711
10716
|
await db.schema
|
|
10712
10717
|
.createTable("todo")
|
|
10713
10718
|
.addColumn("id", "text", (c) => c.primaryKey())
|
|
10719
|
+
.addColumn("userId", "text", (c) => c.notNull())
|
|
10714
10720
|
.addColumn("title", "text", (c) => c.notNull())
|
|
10715
10721
|
.addColumn("done", "integer", (c) => c.notNull().defaultTo(0))
|
|
10716
10722
|
.addColumn("createdAt", "text", (c) =>
|
|
@@ -10736,6 +10742,8 @@ var todos_controller_default = {
|
|
|
10736
10742
|
Patch,
|
|
10737
10743
|
Post,
|
|
10738
10744
|
} from '@nestjs/common';
|
|
10745
|
+
import { Session } from '@thallesp/nestjs-better-auth';
|
|
10746
|
+
import type { UserSession } from '@thallesp/nestjs-better-auth';
|
|
10739
10747
|
import { TodosService } from './todos.service';
|
|
10740
10748
|
|
|
10741
10749
|
@Controller('todos')
|
|
@@ -10743,23 +10751,23 @@ export class TodosController {
|
|
|
10743
10751
|
constructor(private readonly todosService: TodosService) {}
|
|
10744
10752
|
|
|
10745
10753
|
@Get()
|
|
10746
|
-
findAll() {
|
|
10747
|
-
return this.todosService.findAll();
|
|
10754
|
+
findAll(@Session() session: UserSession) {
|
|
10755
|
+
return this.todosService.findAll(session.user.id);
|
|
10748
10756
|
}
|
|
10749
10757
|
|
|
10750
10758
|
@Post()
|
|
10751
|
-
create(@Body('title') title: string) {
|
|
10752
|
-
return this.todosService.create(title);
|
|
10759
|
+
create(@Session() session: UserSession, @Body('title') title: string) {
|
|
10760
|
+
return this.todosService.create(session.user.id, title);
|
|
10753
10761
|
}
|
|
10754
10762
|
|
|
10755
10763
|
@Patch(':id/toggle')
|
|
10756
|
-
toggle(@Param('id') id: string) {
|
|
10757
|
-
return this.todosService.toggle(id);
|
|
10764
|
+
toggle(@Session() session: UserSession, @Param('id') id: string) {
|
|
10765
|
+
return this.todosService.toggle(session.user.id, id);
|
|
10758
10766
|
}
|
|
10759
10767
|
|
|
10760
10768
|
@Delete(':id')
|
|
10761
|
-
remove(@Param('id') id: string) {
|
|
10762
|
-
return this.todosService.remove(id);
|
|
10769
|
+
remove(@Session() session: UserSession, @Param('id') id: string) {
|
|
10770
|
+
return this.todosService.remove(session.user.id, id);
|
|
10763
10771
|
}
|
|
10764
10772
|
}`
|
|
10765
10773
|
};
|
|
@@ -10824,18 +10832,26 @@ export type { Todo } from './todos/todos.service';`
|
|
|
10824
10832
|
var web_todos_route_default = {
|
|
10825
10833
|
filename: "apps/web/app/api/todos/route.ts",
|
|
10826
10834
|
template: `import { NextResponse } from 'next/server';
|
|
10835
|
+
import { headers } from 'next/headers';
|
|
10827
10836
|
import { inject } from '@/lib/nest';
|
|
10837
|
+
import { auth } from '@<%= projectName %>/auth';
|
|
10828
10838
|
import { TodosService } from '@<%= projectName %>/api';
|
|
10829
10839
|
|
|
10830
10840
|
export async function GET() {
|
|
10841
|
+
const session = await auth.api.getSession({ headers: await headers() });
|
|
10842
|
+
if (!session) return new NextResponse('Unauthorized', { status: 401 });
|
|
10831
10843
|
const todos = await inject(TodosService);
|
|
10832
|
-
return NextResponse.json(await todos.findAll());
|
|
10844
|
+
return NextResponse.json(await todos.findAll(session.user.id));
|
|
10833
10845
|
}
|
|
10834
10846
|
|
|
10835
10847
|
export async function POST(req: Request) {
|
|
10848
|
+
const session = await auth.api.getSession({ headers: await headers() });
|
|
10849
|
+
if (!session) return new NextResponse('Unauthorized', { status: 401 });
|
|
10836
10850
|
const { title } = await req.json();
|
|
10837
10851
|
const todos = await inject(TodosService);
|
|
10838
|
-
return NextResponse.json(await todos.create(title), {
|
|
10852
|
+
return NextResponse.json(await todos.create(session.user.id, title), {
|
|
10853
|
+
status: 201,
|
|
10854
|
+
});
|
|
10839
10855
|
}`
|
|
10840
10856
|
};
|
|
10841
10857
|
|
|
@@ -10843,13 +10859,17 @@ export async function POST(req: Request) {
|
|
|
10843
10859
|
var web_todos_id_route_default = {
|
|
10844
10860
|
filename: "apps/web/app/api/todos/[id]/route.ts",
|
|
10845
10861
|
template: `import { NextResponse } from 'next/server';
|
|
10862
|
+
import { headers } from 'next/headers';
|
|
10846
10863
|
import { inject } from '@/lib/nest';
|
|
10864
|
+
import { auth } from '@<%= projectName %>/auth';
|
|
10847
10865
|
import { TodosService } from '@<%= projectName %>/api';
|
|
10848
10866
|
|
|
10849
10867
|
export async function DELETE(_req: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
10868
|
+
const session = await auth.api.getSession({ headers: await headers() });
|
|
10869
|
+
if (!session) return new NextResponse('Unauthorized', { status: 401 });
|
|
10850
10870
|
const { id } = await params;
|
|
10851
10871
|
const todos = await inject(TodosService);
|
|
10852
|
-
await todos.remove(id);
|
|
10872
|
+
await todos.remove(session.user.id, id);
|
|
10853
10873
|
return new NextResponse(null, { status: 204 });
|
|
10854
10874
|
}`
|
|
10855
10875
|
};
|
|
@@ -10858,13 +10878,17 @@ export async function DELETE(_req: Request, { params }: { params: Promise<{ id:
|
|
|
10858
10878
|
var web_todos_toggle_route_default = {
|
|
10859
10879
|
filename: "apps/web/app/api/todos/[id]/toggle/route.ts",
|
|
10860
10880
|
template: `import { NextResponse } from 'next/server';
|
|
10881
|
+
import { headers } from 'next/headers';
|
|
10861
10882
|
import { inject } from '@/lib/nest';
|
|
10883
|
+
import { auth } from '@<%= projectName %>/auth';
|
|
10862
10884
|
import { TodosService } from '@<%= projectName %>/api';
|
|
10863
10885
|
|
|
10864
10886
|
export async function PATCH(_req: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
10887
|
+
const session = await auth.api.getSession({ headers: await headers() });
|
|
10888
|
+
if (!session) return new NextResponse('Unauthorized', { status: 401 });
|
|
10865
10889
|
const { id } = await params;
|
|
10866
10890
|
const todos = await inject(TodosService);
|
|
10867
|
-
return NextResponse.json(await todos.toggle(id));
|
|
10891
|
+
return NextResponse.json(await todos.toggle(session.user.id, id));
|
|
10868
10892
|
}`
|
|
10869
10893
|
};
|
|
10870
10894
|
|