fix: query custom text id fields
This commit is contained in:
@@ -103,7 +103,7 @@ export const sanitizeQueryValue = ({ field, path, operator, val, hasCustomID }:
|
||||
formattedValue = createArrayFromCommaDelineated(formattedValue);
|
||||
}
|
||||
|
||||
if (path !== '_id') {
|
||||
if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {
|
||||
if (operator === 'contains') {
|
||||
formattedValue = { $regex: formattedValue, $options: 'i' };
|
||||
}
|
||||
|
||||
@@ -274,6 +274,14 @@ describe('collections-rest', () => {
|
||||
expect(foundDoc.id).toEqual(doc.id);
|
||||
});
|
||||
|
||||
it('should query', async () => {
|
||||
const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`;
|
||||
const { doc } = await client.create({ slug: customIdSlug, data: { id: customId, name: 'custom-id-name' } });
|
||||
const { result } = await client.find({ slug: customIdSlug, query: { id: { like: 'custom' } } });
|
||||
|
||||
expect(result.docs.map(({ id }) => id)).toContain(doc.id);
|
||||
});
|
||||
|
||||
it('should update', async () => {
|
||||
const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`;
|
||||
const { doc } = await client.create({ slug: customIdSlug, data: { id: customId, data: { name: 'custom-id-name' } } });
|
||||
|
||||
Reference in New Issue
Block a user