- City Access
+ Разрешения для города
{cities.map((city) => (
diff --git a/src/services/galleryService.ts b/src/services/galleryService.ts
index ecb15a0..78c0c9e 100644
--- a/src/services/galleryService.ts
+++ b/src/services/galleryService.ts
@@ -2,7 +2,15 @@ import axios from '../utils/api';
import { GalleryImage } from '../types';
export const galleryService = {
- createImage: async (articleId: string, imageData: Omit) => {
+ createImage: async (articleId: string, imageData: {
+ url: string;
+ caption: string;
+ alt: string;
+ width: number;
+ height: number;
+ size: number;
+ format: string
+ }) => {
const { data } = await axios.post(`/gallery/article/${articleId}`, imageData);
return data;
},
diff --git a/src/services/imageService.ts b/src/services/imageService.ts
deleted file mode 100644
index 53d0b4c..0000000
--- a/src/services/imageService.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import axios from '../utils/api';
-import { ImageResolution, UploadedImage } from '../types/image';
-
-export async function uploadImage(
- file: File,
- resolution: ImageResolution,
- onProgress?: (progress: number) => void
-): Promise {
- // Get pre-signed URL for S3 upload
- const { data: { uploadUrl, imageId } } = await axios.post('/images/upload-url', {
- fileName: file.name,
- fileType: file.type,
- resolution: resolution.id
- });
-
- // Upload to S3
- await axios.put(uploadUrl, file, {
- headers: {
- 'Content-Type': file.type
- },
- onUploadProgress: (progressEvent) => {
- if (progressEvent.total) {
- const progress = Math.round((progressEvent.loaded * 100) / progressEvent.total);
- onProgress?.(progress);
- }
- }
- });
-
- // Get the processed image details
- const { data: image } = await axios.get(`/images/${imageId}`);
- return image;
-}
\ No newline at end of file
diff --git a/src/types/auth.ts b/src/types/auth.ts
index c4b17d0..6b5c4c9 100644
--- a/src/types/auth.ts
+++ b/src/types/auth.ts
@@ -1,8 +1,8 @@
-import { Category, City } from './index';
+import { CategoryName, City } from './index';
export interface UserPermissions {
categories: {
- [key in Category]?: {
+ [key in CategoryName]?: {
create: boolean;
edit: boolean;
delete: boolean;
diff --git a/src/types/index.ts b/src/types/index.ts
index 49e2ad6..0b6e67d 100644
--- a/src/types/index.ts
+++ b/src/types/index.ts
@@ -4,6 +4,7 @@ export interface Article {
excerpt: string;
content: string;
category: Category;
+ categoryId: number;
city: City;
author: Author;
coverImage: string;
@@ -29,5 +30,25 @@ export interface Author {
bio: string;
}
-export type Category = 'Film' | 'Theater' | 'Music' | 'Sports' | 'Art' | 'Legends' | 'Anniversaries' | 'Memory';
-export type City = 'New York' | 'London';
\ No newline at end of file
+export interface Category {
+ id: number;
+ name: CategoryName;
+}
+
+export type CategoryName = 'Film' | 'Theater' | 'Music' | 'Sports' | 'Art' | 'Legends' | 'Anniversaries' | 'Memory';
+export type City = 'New York' | 'London';
+
+export const CategoryNames: CategoryName[] = [
+ 'Film', 'Theater', 'Music', 'Sports', 'Art', 'Legends', 'Anniversaries', 'Memory'
+];
+
+export const CategoryMap: Record = {
+ Film: 1,
+ Theater: 2,
+ Music: 3,
+ Sports: 4,
+ Art: 5,
+ Legends: 6,
+ Anniversaries: 7,
+ Memory: 8,
+};
\ No newline at end of file
diff --git a/src/utils/categories.ts b/src/utils/categories.ts
new file mode 100644
index 0000000..eb96e1a
--- /dev/null
+++ b/src/utils/categories.ts
@@ -0,0 +1,28 @@
+import { Category, CategoryName } from '../types';
+
+export const categories: Category[] = [
+ { id: 1, name: 'Film' },
+ { id: 2, name: 'Theater' },
+ { id: 3, name: 'Music' },
+ { id: 4, name: 'Sports' },
+ { id: 5, name: 'Art' },
+ { id: 6, name: 'Legends' },
+ { id: 7, name: 'Anniversaries' },
+ { id: 8, name: 'Memory' }
+];
+
+export function getCategoryName(id: number): CategoryName {
+ const category = categories.find(c => c.id === id);
+ if (!category) {
+ throw new Error(`Invalid category ID: ${id}`);
+ }
+ return category.name;
+}
+
+export function getCategoryId(name: CategoryName): number {
+ const category = categories.find(c => c.name === name);
+ if (!category) {
+ throw new Error(`Invalid category name: ${name}`);
+ }
+ return category.id;
+}
\ No newline at end of file
diff --git a/src/utils/permissions.ts b/src/utils/permissions.ts
index d3390cf..58b4857 100644
--- a/src/utils/permissions.ts
+++ b/src/utils/permissions.ts
@@ -2,12 +2,12 @@ import { Category, City } from '../types';
import { User } from '../types/auth';
export const checkPermission = (
- user: User,
- category: Category,
- action: 'create' | 'edit' | 'delete'
+ user: User,
+ category: Category,
+ action: 'create' | 'edit' | 'delete'
): boolean => {
if (user.permissions.isAdmin) return true;
- return !!user.permissions.categories[category]?.[action];
+ return !!user.permissions.categories[category.name]?.[action];
};
export const checkCityAccess = (user: User, city: City): boolean => {
diff --git a/tsconfig.json b/tsconfig.json
index 6cd2095..47cd287 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -5,10 +5,18 @@
{ "path": "./tsconfig.node.json" }
],
"compilerOptions": {
- "target": "esnext", // Compile to a modern ECMAScript version that supports ES modules
- "module": "esnext", // Use ES module syntax for module code generation
+ "target": "ESNext", // Compile to a modern ECMAScript version that supports ES modules
+ "module": "ESNext", // Use ES module syntax for module code generation
+ "strict": true,
+ "strictNullChecks": true,
+ "skipLibCheck": true,
+ "forceConsistentCasingInFileNames": true,
"moduleResolution": "node", // Use Node.js style module resolution
"esModuleInterop": true, // Enables default imports from modules with no default export
"outDir": "./dist" // Output directory for compiled files
- }
+ },
+ "ts-node": {
+ "esm": true
+ },
+ "include": ["src/**/*.ts"]
}