-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
317 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
PRAGMA foreign_keys=OFF;--> statement-breakpoint | ||
CREATE TABLE `__new_chains` ( | ||
`id` text PRIMARY KEY NOT NULL, | ||
`resource_type` text DEFAULT 'chain' NOT NULL, | ||
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL, | ||
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL, | ||
`name` text NOT NULL | ||
); | ||
--> statement-breakpoint | ||
INSERT INTO `__new_chains`("id", "resource_type", "created_at", "updated_at", "name") SELECT "id", "resource_type", "created_at", "updated_at", "name" FROM `chains`;--> statement-breakpoint | ||
DROP TABLE `chains`;--> statement-breakpoint | ||
ALTER TABLE `__new_chains` RENAME TO `chains`;--> statement-breakpoint | ||
PRAGMA foreign_keys=ON;--> statement-breakpoint | ||
CREATE TABLE `__new_users` ( | ||
`id` text PRIMARY KEY NOT NULL, | ||
`resource_type` text DEFAULT 'user' NOT NULL, | ||
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL, | ||
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL, | ||
`telegram_chat_id` integer NOT NULL, | ||
`role` text DEFAULT 'user' NOT NULL | ||
); | ||
--> statement-breakpoint | ||
INSERT INTO `__new_users`("id", "resource_type", "created_at", "updated_at", "telegram_chat_id") SELECT "id", "resource_type", "created_at", "updated_at", "telegram_chat_id" FROM `users`;--> statement-breakpoint | ||
DROP TABLE `users`;--> statement-breakpoint | ||
ALTER TABLE `__new_users` RENAME TO `users`;--> statement-breakpoint | ||
CREATE UNIQUE INDEX `users_telegramChatId_unique` ON `users` (`telegram_chat_id`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
{ | ||
"version": "6", | ||
"dialect": "sqlite", | ||
"id": "132ca062-77cb-4b35-a3c8-3dbe452350ce", | ||
"prevId": "2b4f22d3-5a7a-44b0-85f8-0c48a86ba4e3", | ||
"tables": { | ||
"chains": { | ||
"name": "chains", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "text", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"resource_type": { | ||
"name": "resource_type", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": "'chain'" | ||
}, | ||
"created_at": { | ||
"name": "created_at", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": "(CURRENT_TIMESTAMP)" | ||
}, | ||
"updated_at": { | ||
"name": "updated_at", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": "(CURRENT_TIMESTAMP)" | ||
}, | ||
"name": { | ||
"name": "name", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {}, | ||
"checkConstraints": {} | ||
}, | ||
"users": { | ||
"name": "users", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "text", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"resource_type": { | ||
"name": "resource_type", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": "'user'" | ||
}, | ||
"created_at": { | ||
"name": "created_at", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": "(CURRENT_TIMESTAMP)" | ||
}, | ||
"updated_at": { | ||
"name": "updated_at", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": "(CURRENT_TIMESTAMP)" | ||
}, | ||
"telegram_chat_id": { | ||
"name": "telegram_chat_id", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"role": { | ||
"name": "role", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": "'user'" | ||
} | ||
}, | ||
"indexes": { | ||
"users_telegramChatId_unique": { | ||
"name": "users_telegramChatId_unique", | ||
"columns": ["telegram_chat_id"], | ||
"isUnique": true | ||
} | ||
}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {}, | ||
"checkConstraints": {} | ||
} | ||
}, | ||
"views": {}, | ||
"enums": {}, | ||
"_meta": { | ||
"schemas": {}, | ||
"tables": {}, | ||
"columns": {} | ||
}, | ||
"internal": { | ||
"indexes": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { inspect, parseArgs } from "node:util"; | ||
import { config } from "dotenv"; | ||
import { z } from "zod"; | ||
import { envSchema } from "../src/shared/context/env.ts"; | ||
|
||
const argsRaw = parseArgs({ | ||
options: { | ||
id: { | ||
type: "string", | ||
}, | ||
}, | ||
}); | ||
|
||
const argsSchema = z.object({ id: z.string().uuid() }); | ||
|
||
const { id } = argsSchema.parse(argsRaw.values); | ||
|
||
const env = envSchema.parse(config().parsed); | ||
|
||
const response = await fetch( | ||
`http://localhost:5173/admin/users/${id}/promote-to-admin`, | ||
{ | ||
method: "PUT", | ||
headers: { | ||
"Content-Type": "application/json", | ||
// biome-ignore lint/style/useNamingConvention: env variables have different convention | ||
Authorization: `Basic ${Buffer.from(`${env.ADMIN_USERNAME}:${env.ADMIN_PASSWORD}`).toString("base64")}`, | ||
}, | ||
}, | ||
); | ||
|
||
const body = await response.json(); | ||
|
||
console.info( | ||
inspect(body, { | ||
depth: Number.POSITIVE_INFINITY, | ||
colors: true, | ||
maxArrayLength: Number.POSITIVE_INFINITY, | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Hono } from "hono"; | ||
import { basicAuth } from "hono/basic-auth"; | ||
import { getContext } from "hono/context-storage"; | ||
import type { Context } from "../../shared/context/context.ts"; | ||
import { usersRoute } from "./users.route.ts"; | ||
|
||
export const adminRoute = new Hono(); | ||
|
||
adminRoute.use((hc, next) => { | ||
const { env } = getContext<Context>().var; | ||
|
||
return basicAuth({ | ||
username: env.ADMIN_USERNAME, | ||
password: env.ADMIN_PASSWORD, | ||
})(hc, next); | ||
}); | ||
|
||
adminRoute.route("/users", usersRoute); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { zValidator } from "@hono/zod-validator"; | ||
import { Hono } from "hono"; | ||
import { z } from "zod"; | ||
import { promoteUserToAdmin } from "../../bl/users/users.bl.ts"; | ||
import { userSchema } from "../../shared/schema/users.ts"; | ||
|
||
export const usersRoute = new Hono(); | ||
|
||
usersRoute.put( | ||
"/:id/promote-to-admin", | ||
zValidator( | ||
"param", | ||
z.object({ | ||
id: z.string(), | ||
}), | ||
), | ||
async (hc) => { | ||
const user = await promoteUserToAdmin(hc.req.param("id")); | ||
|
||
return hc.json(userDtoSchema.parse(user)); | ||
}, | ||
); | ||
|
||
const userDtoSchema = userSchema.omit({ | ||
resourceType: true, | ||
createdAt: true, | ||
updatedAt: true, | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.