Worked on zone objects, tile tags and searching

This commit is contained in:
2024-07-04 02:07:55 +02:00
parent d702612cb1
commit 829a2ef726
16 changed files with 330 additions and 13 deletions

View File

@ -0,0 +1,14 @@
import prisma from '../utilities/Prisma'; // Import the global Prisma instance
import { Object } from '@prisma/client'
class ObjectRepository {
getById(id: string): Promise<Object | null> {
return prisma.object.findUnique({
where: {
id,
},
});
}
}
export default new ObjectRepository();

View File

@ -0,0 +1,45 @@
import prisma from '../utilities/Prisma'; // Import the global Prisma instance
import { TileTag } from '@prisma/client'
class TileTagRepository {
async upsertTileTag(tile: string, tags: string[]): Promise<TileTag> {
return prisma.tileTag.upsert({
where: { tile },
create: {
tile,
tags: tags,
},
update: {
tags: tags,
},
});
}
async getTileTag(tile: string): Promise<TileTag | null> {
return prisma.tileTag.findUnique({
where: { tile },
});
}
async deleteTileTag(tile: string): Promise<TileTag> {
return prisma.tileTag.delete({
where: { tile },
});
}
async searchTilesByTags(tags: string[]): Promise<TileTag[]> {
return prisma.tileTag.findMany({
where: {
tags: {
array_contains: tags,
} as any, // Type assertion needed due to Json field
},
});
}
async getAllTileTags(): Promise<TileTag[]> {
return prisma.tileTag.findMany();
}
}
export default new TileTagRepository();